Commit 3487ae4b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Change CLFunction::source to a unique_ptr

We don't currently destruct CLFunctions, but this makes it
clear that each SourceInfo belongs to a single CLFunction.
parent 6fca035b
......@@ -224,13 +224,13 @@ void ASTInterpreter::gcVisit(GCVisitor* visitor) {
}
ASTInterpreter::ASTInterpreter(CompiledFunction* compiled_function)
: compiled_func(compiled_function), source_info(compiled_function->clfunc->source), scope_info(0), phis(NULL),
: compiled_func(compiled_function), source_info(compiled_function->clfunc->source.get()), scope_info(0), phis(NULL),
current_block(0), current_inst(0), last_exception(NULL, NULL, NULL), passed_closure(0), created_closure(0),
generator(0), edgecount(0), frame_info(ExcInfo(NULL, NULL, NULL)) {
CLFunction* f = compiled_function->clfunc;
if (!source_info->cfg)
source_info->cfg = computeCFG(f->source, f->source->body);
source_info->cfg = computeCFG(f->source.get(), f->source->body);
scope_info = source_info->getScopeInfo();
......@@ -1228,7 +1228,7 @@ Box* astInterpretFunction(CompiledFunction* cf, int nargs, Box* closure, Box* ge
ASTInterpreter interpreter(cf);
ScopeInfo* scope_info = cf->clfunc->source->getScopeInfo();
SourceInfo* source_info = cf->clfunc->source;
SourceInfo* source_info = cf->clfunc->source.get();
if (unlikely(scope_info->usesNameLookup())) {
interpreter.setBoxedLocals(new BoxedDict());
}
......@@ -1254,7 +1254,7 @@ Box* astInterpretFunctionEval(CompiledFunction* cf, Box* globals, Box* boxedLoca
interpreter.setBoxedLocals(boxedLocals);
ScopeInfo* scope_info = cf->clfunc->source->getScopeInfo();
SourceInfo* source_info = cf->clfunc->source;
SourceInfo* source_info = cf->clfunc->source.get();
assert(!cf->clfunc->source->scoping->areGlobalsFromModule());
assert(globals);
......@@ -1276,7 +1276,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl
ASTInterpreter interpreter(cf);
ScopeInfo* scope_info = cf->clfunc->source->getScopeInfo();
SourceInfo* source_info = cf->clfunc->source;
SourceInfo* source_info = cf->clfunc->source.get();
assert(cf->clfunc->source->scoping->areGlobalsFromModule());
interpreter.setGlobals(source_info->parent_module);
......
......@@ -186,7 +186,7 @@ CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, E
assert((entry_descriptor != NULL) + (spec != NULL) == 1);
SourceInfo* source = f->source;
SourceInfo* source = f->source.get();
assert(source);
std::string name = source->getName();
......@@ -313,11 +313,11 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
ScopingAnalysis* scoping = new ScopingAnalysis(m);
SourceInfo* si = new SourceInfo(bm, scoping, m, m->body);
CLFunction* cl_f = new CLFunction(0, 0, false, false, si);
std::unique_ptr<SourceInfo> si(new SourceInfo(bm, scoping, m, m->body));
bm->setattr("__doc__", si->getDocString(), NULL);
CLFunction* cl_f = new CLFunction(0, 0, false, false, std::move(si));
EffortLevel effort = initialEffort();
assert(scoping->areGlobalsFromModule());
......@@ -358,8 +358,8 @@ template <typename AST_Type> CLFunction* compileForEvalOrExec(AST_Type* source,
ScopingAnalysis* scoping = new ScopingAnalysis(source, false);
SourceInfo* si = new SourceInfo(getCurrentModule(), scoping, source, body);
CLFunction* cl_f = new CLFunction(0, 0, false, false, si);
std::unique_ptr<SourceInfo> si(new SourceInfo(getCurrentModule(), scoping, source, body));
CLFunction* cl_f = new CLFunction(0, 0, false, false, std::move(si));
return cl_f;
}
......
......@@ -2591,12 +2591,12 @@ CLFunction* wrapFunction(AST* node, AST_arguments* args, const std::vector<AST_s
CLFunction*& cl = made[node];
if (cl == NULL) {
SourceInfo* si = new SourceInfo(source->parent_module, source->scoping, node, body);
std::unique_ptr<SourceInfo> si(new SourceInfo(source->parent_module, source->scoping, node, body));
if (args)
cl = new CLFunction(args->args.size(), args->defaults.size(), args->vararg.str().size(),
args->kwarg.str().size(), si);
args->kwarg.str().size(), std::move(si));
else
cl = new CLFunction(0, 0, 0, 0, si);
cl = new CLFunction(0, 0, 0, 0, std::move(si));
}
return cl;
}
......
......@@ -497,7 +497,7 @@ static const LineInfo* lineInfoForFrame(PythonFrameIteratorImpl& frame_it) {
auto* cf = frame_it.getCF();
assert(cf);
auto source = cf->clfunc->source;
auto source = cf->clfunc->source.get();
// Hack: the "filename" for eval and exec statements is "<string>", not the filename
// of the parent module. We can't currently represent this the same way that CPython does
......
......@@ -271,7 +271,7 @@ public:
int num_defaults;
bool takes_varargs, takes_kwargs;
SourceInfo* source;
std::unique_ptr<SourceInfo> source;
ParamNames param_names;
FunctionList
......@@ -287,14 +287,15 @@ public:
const std::vector<const std::string*>*);
InternalCallable internal_callable = NULL;
CLFunction(int num_args, int num_defaults, bool takes_varargs, bool takes_kwargs, SourceInfo* source)
CLFunction(int num_args, int num_defaults, bool takes_varargs, bool takes_kwargs,
std::unique_ptr<SourceInfo> source)
: num_args(num_args), num_defaults(num_defaults), takes_varargs(takes_varargs), takes_kwargs(takes_kwargs),
source(source), param_names(source->ast), always_use_version(NULL) {
source(std::move(source)), param_names(this->source->ast), always_use_version(NULL) {
assert(num_args >= num_defaults);
}
CLFunction(int num_args, int num_defaults, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names)
: num_args(num_args), num_defaults(num_defaults), takes_varargs(takes_varargs), takes_kwargs(takes_kwargs),
source(NULL), param_names(param_names), always_use_version(NULL) {
source(nullptr), param_names(param_names), always_use_version(NULL) {
assert(num_args >= num_defaults);
}
......
c = compile("a = 1; print a", "test.py", "exec")
print type(c)
print type(c), c.co_filename, c.co_name
print
a = 0
......
......@@ -36,7 +36,7 @@ TEST_F(AnalysisTest, augassign) {
ASSERT_FALSE(scope_info->getScopeTypeOfName(module->interned_strings->get("a")) == ScopeInfo::VarScopeType::GLOBAL);
ASSERT_FALSE(scope_info->getScopeTypeOfName(module->interned_strings->get("b")) == ScopeInfo::VarScopeType::GLOBAL);
SourceInfo* si = new SourceInfo(createModule("augassign", fn), scoping, func, func->body);
SourceInfo* si = new SourceInfo(createModule("augassign", fn), scoping, func, func->body, fn);
CFG* cfg = computeCFG(si, func->body);
LivenessAnalysis* liveness = computeLivenessInfo(cfg);
......@@ -64,7 +64,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
ScopeInfo* scope_info = scoping->getScopeInfoForNode(func);
SourceInfo* si = new SourceInfo(createModule("osr" + std::to_string((is_osr << 1) + i_maybe_undefined), fn),
scoping, func, func->body);
scoping, func, func->body, fn);
CFG* cfg = computeCFG(si, func->body);
LivenessAnalysis* liveness = computeLivenessInfo(cfg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment