Commit 03aedad4 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #653 from tjhance/dont-guard-builtin

Don't guard types sometimes
parents fc8b1d26 ede5b9a9
......@@ -218,6 +218,8 @@ public:
template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any());
bool isConstant() { return is_constant; }
private:
Rewriter* rewriter;
......
......@@ -683,7 +683,7 @@ BoxedDict* Box::getDict() {
static StatCounter box_getattr_slowpath("slowpath_box_getattr");
Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) {
if (rewrite_args)
if (rewrite_args && !rewrite_args->obj_cls_guarded)
rewrite_args->obj->addAttrGuard(offsetof(Box, cls), (intptr_t)cls);
#if 0
......@@ -733,7 +733,10 @@ Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) {
REWRITE_ABORTED("");
rewrite_args = NULL;
} else {
rewrite_args->obj->addAttrGuard(cls->attrs_offset + offsetof(HCAttrs, hcls), (intptr_t)hcls);
if (!(rewrite_args->obj->isConstant() && cls == type_cls
&& static_cast<BoxedClass*>(this)->is_constant)) {
rewrite_args->obj->addAttrGuard(cls->attrs_offset + offsetof(HCAttrs, hcls), (intptr_t)hcls);
}
if (hcls->type == HiddenClass::SINGLETON)
hcls->addDependence(rewrite_args->rewriter);
}
......@@ -985,6 +988,9 @@ Box* typeLookup(BoxedClass* cls, llvm::StringRef attr, GetattrRewriteArgs* rewri
assert(rewrite_args->obj == obj_saved);
} else {
rewrite_args->obj = rewrite_args->rewriter->loadConst((intptr_t)base, Location::any());
if (static_cast<BoxedClass*>(base)->is_constant) {
rewrite_args->obj_cls_guarded = true;
}
}
val = base->getattr(attr, rewrite_args);
assert(rewrite_args->out_success);
......@@ -5042,6 +5048,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
if (rewriter.get()) {
RewriterVar* builtins = rewriter->loadConst((intptr_t)builtins_module, Location::any());
GetattrRewriteArgs rewrite_args(rewriter.get(), builtins, rewriter->getReturnDestination());
rewrite_args.obj_cls_guarded = true; // always builtin module
rtn = builtins_module->getattr(name->s(), &rewrite_args);
if (!rtn || !rewrite_args.out_success) {
......
......@@ -28,6 +28,7 @@ struct GetattrRewriteArgs {
RewriterVar* out_rtn;
bool obj_hcls_guarded;
bool obj_cls_guarded;
GetattrRewriteArgs(Rewriter* rewriter, RewriterVar* obj, Location destination)
: rewriter(rewriter),
......@@ -35,7 +36,8 @@ struct GetattrRewriteArgs {
destination(destination),
out_success(false),
out_rtn(NULL),
obj_hcls_guarded(false) {}
obj_hcls_guarded(false),
obj_cls_guarded(false) {}
};
struct SetattrRewriteArgs {
......
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