Skip to content

Commit 5ca145d

Browse files
committed
Merge pull request #992 from kmod/docs
Improve comments, rename CLFunction
2 parents 8e2a094 + 6e81dc4 commit 5ca145d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1516
-1256
lines changed

src/capi/typeobject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,8 +1915,8 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce
19151915
sanity checks. I'll buy the first person to
19161916
point out a bug in this reasoning a beer. */
19171917
} else if (offset == offsetof(BoxedClass, tp_descr_get) && descr->cls == function_cls
1918-
&& static_cast<BoxedFunction*>(descr)->f->always_use_version) {
1919-
CompiledFunction* cf = static_cast<BoxedFunction*>(descr)->f->always_use_version;
1918+
&& static_cast<BoxedFunction*>(descr)->md->always_use_version) {
1919+
CompiledFunction* cf = static_cast<BoxedFunction*>(descr)->md->always_use_version;
19201920
if (cf->exception_style == CXX) {
19211921
type->tpp_descr_get = (descrgetfunc)cf->code;
19221922
specific = (void*)slot_tp_tpp_descr_get;

src/codegen/ast_interpreter.cpp

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

src/codegen/ast_interpreter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AST_Jump;
2929
class Box;
3030
class BoxedClosure;
3131
class BoxedDict;
32-
struct CLFunction;
32+
struct FunctionMetadata;
3333
struct LineInfo;
3434

3535
extern const void* interpreter_instr_addr;
@@ -70,15 +70,15 @@ struct Value {
7070
Value(Box* o, RewriterVar* var) : o(o), var(var) {}
7171
};
7272

73-
Box* astInterpretFunction(CLFunction* f, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, Box* arg3,
74-
Box** args);
75-
Box* astInterpretFunctionEval(CLFunction* cf, Box* globals, Box* boxedLocals);
76-
Box* astInterpretDeopt(CLFunction* cf, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val,
73+
Box* astInterpretFunction(FunctionMetadata* f, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2,
74+
Box* arg3, Box** args);
75+
Box* astInterpretFunctionEval(FunctionMetadata* cf, Box* globals, Box* boxedLocals);
76+
Box* astInterpretDeopt(FunctionMetadata* cf, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val,
7777
FrameStackState frame_state);
7878

7979
AST_stmt* getCurrentStatementForInterpretedFrame(void* frame_ptr);
8080
Box* getGlobalsForInterpretedFrame(void* frame_ptr);
81-
CLFunction* getCLForInterpretedFrame(void* frame_ptr);
81+
FunctionMetadata* getMDForInterpretedFrame(void* frame_ptr);
8282
struct FrameInfo;
8383
FrameInfo* getFrameInfoForInterpretedFrame(void* frame_ptr);
8484
BoxedClosure* passedClosureForInterpretedFrame(void* frame_ptr);

src/codegen/codegen.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ namespace pyston {
3838

3939
DS_DEFINE_RWLOCK(codegen_rwlock);
4040

41-
CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, std::unique_ptr<SourceInfo> source)
41+
FunctionMetadata::FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs,
42+
std::unique_ptr<SourceInfo> source)
4243
: code_obj(NULL),
4344
num_args(num_args),
4445
takes_varargs(takes_varargs),
@@ -50,7 +51,7 @@ CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, std:
5051
internal_callable(NULL, NULL) {
5152
}
5253

53-
CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names)
54+
FunctionMetadata::FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names)
5455
: code_obj(NULL),
5556
num_args(num_args),
5657
takes_varargs(takes_varargs),
@@ -62,21 +63,21 @@ CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, cons
6263
internal_callable(NULL, NULL) {
6364
}
6465

65-
BoxedCode* CLFunction::getCode() {
66+
BoxedCode* FunctionMetadata::getCode() {
6667
if (!code_obj) {
6768
code_obj = new BoxedCode(this);
68-
// CLFunctions don't currently participate in GC. They actually never get freed currently.
69+
// FunctionMetadatas don't currently participate in GC. They actually never get freed currently.
6970
gc::registerPermanentRoot(code_obj);
7071
}
7172
return code_obj;
7273
}
7374

74-
void CLFunction::addVersion(CompiledFunction* compiled) {
75+
void FunctionMetadata::addVersion(CompiledFunction* compiled) {
7576
assert(compiled);
7677
assert((compiled->spec != NULL) + (compiled->entry_descriptor != NULL) == 1);
77-
assert(compiled->clfunc == NULL);
78+
assert(compiled->md == NULL);
7879
assert(compiled->code);
79-
compiled->clfunc = this;
80+
compiled->md = this;
8081

8182
if (compiled->entry_descriptor == NULL) {
8283
bool could_have_speculations = (source.get() != NULL);

src/codegen/codegen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct GlobalState {
7474
llvm::Type* llvm_opaque_type;
7575
llvm::Type* llvm_boxedstring_type_ptr, *llvm_dict_type_ptr, *llvm_aststmt_type_ptr, *llvm_astexpr_type_ptr;
7676
llvm::Type* llvm_frame_info_type;
77-
llvm::Type* llvm_clfunction_type_ptr, *llvm_closure_type_ptr, *llvm_generator_type_ptr;
77+
llvm::Type* llvm_functionmetadata_type_ptr, *llvm_closure_type_ptr, *llvm_generator_type_ptr;
7878
llvm::Type* llvm_module_type_ptr, *llvm_bool_type_ptr;
7979
llvm::Type* llvm_excinfo_type;
8080
llvm::Type* i1, *i8, *i8_ptr, *i32, *i64, *void_, *double_;

src/codegen/compvars.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ ConcreteCompilerVariable* UnknownType::hasnext(IREmitter& emitter, const OpInfo&
810810
return boolFromI1(emitter, rtn_val);
811811
}
812812

813-
CompilerVariable* makeFunction(IREmitter& emitter, CLFunction* f, CompilerVariable* closure, llvm::Value* globals,
813+
CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata* f, CompilerVariable* closure, llvm::Value* globals,
814814
const std::vector<ConcreteCompilerVariable*>& defaults) {
815-
// Unlike the CLFunction*, which can be shared between recompilations, the Box* around it
815+
// Unlike the FunctionMetadata*, which can be shared between recompilations, the Box* around it
816816
// should be created anew every time the functiondef is encountered
817817

818818
llvm::Value* closure_v;
@@ -844,8 +844,9 @@ CompilerVariable* makeFunction(IREmitter& emitter, CLFunction* f, CompilerVariab
844844
// We know this function call can't throw, so it's safe to use emitter.getBuilder()->CreateCall() rather than
845845
// emitter.createCall().
846846
llvm::Value* boxed = emitter.getBuilder()->CreateCall(
847-
g.funcs.boxCLFunction, std::vector<llvm::Value*>{ embedRelocatablePtr(f, g.llvm_clfunction_type_ptr), closure_v,
848-
globals, scratch, getConstantInt(defaults.size(), g.i64) });
847+
g.funcs.createFunctionFromMetadata,
848+
std::vector<llvm::Value*>{ embedRelocatablePtr(f, g.llvm_functionmetadata_type_ptr), closure_v, globals,
849+
scratch, getConstantInt(defaults.size(), g.i64) });
849850

850851
if (convertedClosure)
851852
convertedClosure->decvref(emitter);
@@ -914,12 +915,12 @@ class AbstractFunctionType : public CompilerType {
914915

915916
static CompilerType* fromRT(BoxedFunction* rtfunc, bool stripfirst) {
916917
std::vector<Sig*> sigs;
917-
CLFunction* clf = rtfunc->f;
918+
FunctionMetadata* md = rtfunc->md;
918919

919920
assert(!rtfunc->can_change_defaults);
920921

921-
for (int i = 0; i < clf->versions.size(); i++) {
922-
CompiledFunction* cf = clf->versions[i];
922+
for (int i = 0; i < md->versions.size(); i++) {
923+
CompiledFunction* cf = md->versions[i];
923924

924925
FunctionSpecialization* fspec = cf->spec;
925926

@@ -1864,14 +1865,14 @@ class NormalObjectType : public ConcreteCompilerType {
18641865
// but I don't think we should be running into that case.
18651866
RELEASE_ASSERT(!rtattr_func->can_change_defaults, "could handle this but unexpected");
18661867

1867-
CLFunction* cl = rtattr_func->f;
1868-
assert(cl);
1868+
FunctionMetadata* md = rtattr_func->md;
1869+
assert(md);
18691870

18701871
ParamReceiveSpec paramspec = rtattr_func->getParamspec();
1871-
if (cl->takes_varargs || paramspec.takes_kwargs)
1872+
if (md->takes_varargs || paramspec.takes_kwargs)
18721873
return NULL;
18731874

1874-
RELEASE_ASSERT(paramspec.num_args == cl->numReceivedArgs(), "");
1875+
RELEASE_ASSERT(paramspec.num_args == md->numReceivedArgs(), "");
18751876
RELEASE_ASSERT(args.size() + 1 >= paramspec.num_args - paramspec.num_defaults
18761877
&& args.size() + 1 <= paramspec.num_args,
18771878
"%d", info.unw_info.current_stmt->lineno);
@@ -1880,9 +1881,9 @@ class NormalObjectType : public ConcreteCompilerType {
18801881
CompiledFunction* best_exception_mismatch = NULL;
18811882
bool found = false;
18821883
// TODO have to find the right version.. similar to resolveclfunc?
1883-
for (int i = 0; i < cl->versions.size(); i++) {
1884-
cf = cl->versions[i];
1885-
assert(cf->spec->arg_types.size() == cl->numReceivedArgs());
1884+
for (int i = 0; i < md->versions.size(); i++) {
1885+
cf = md->versions[i];
1886+
assert(cf->spec->arg_types.size() == md->numReceivedArgs());
18861887

18871888
bool fits = true;
18881889
for (int j = 0; j < args.size(); j++) {
@@ -1914,7 +1915,7 @@ class NormalObjectType : public ConcreteCompilerType {
19141915
RELEASE_ASSERT(cf->code, "");
19151916

19161917
std::vector<llvm::Type*> arg_types;
1917-
RELEASE_ASSERT(paramspec.num_args == cl->numReceivedArgs(), "");
1918+
RELEASE_ASSERT(paramspec.num_args == md->numReceivedArgs(), "");
19181919
for (int i = 0; i < paramspec.num_args; i++) {
19191920
// TODO support passing unboxed values as arguments
19201921
assert(cf->spec->arg_types[i]->llvmType() == g.llvm_value_type_ptr);

src/codegen/compvars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ UnboxedSlice extractSlice(CompilerVariable* slice);
441441
#if 0
442442
CompilerVariable* makeUnicode(IREmitter& emitter, llvm::StringRef);
443443
#endif
444-
CompilerVariable* makeFunction(IREmitter& emitter, CLFunction*, CompilerVariable* closure, llvm::Value* globals,
444+
CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata*, CompilerVariable* closure, llvm::Value* globals,
445445
const std::vector<ConcreteCompilerVariable*>& defaults);
446446
ConcreteCompilerVariable* undefVariable();
447447
CompilerVariable* makeTuple(const std::vector<CompilerVariable*>& elts);

src/codegen/irgen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff
974974
return os.str();
975975
}
976976

977-
CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames* param_names,
977+
CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names,
978978
const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
979979
ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix) {
980980
Timer _t("in doCompile");
@@ -1093,7 +1093,7 @@ CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames*
10931093
else
10941094
phis = computeRequiredPhis(*param_names, source->cfg, liveness, source->getScopeInfo());
10951095

1096-
IRGenState irstate(clfunc, cf, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo);
1096+
IRGenState irstate(md, cf, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo);
10971097

10981098
emitBBs(&irstate, types, entry_descriptor, blocks);
10991099

src/codegen/irgen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern const std::string PASSED_GENERATOR_NAME;
113113
InternedString getIsDefinedName(InternedString name, InternedStringPool& interned_strings);
114114
bool isIsDefinedName(llvm::StringRef name);
115115

116-
CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames* param_names,
116+
CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names,
117117
const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
118118
ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix);
119119

0 commit comments

Comments
 (0)