Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
6c22df2f
Commit
6c22df2f
authored
Mar 22, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
e14f5cdc
' into refcounting
Conflicts: src/runtime/objmodel.cpp
parents
7b06e12e
e14f5cdc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
107 deletions
+80
-107
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+80
-103
test/tests/binops_subclass.py
test/tests/binops_subclass.py
+0
-4
No files found.
src/runtime/objmodel.cpp
View file @
6c22df2f
...
...
@@ -4958,148 +4958,125 @@ extern "C" Box* runtimeCallCapi(Box* obj, ArgPassSpec argspec, Box* arg1, Box* a
}
template
<
Rewritable
rewritable
>
Box
*
binopInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
bool
inplace
,
BinopRewriteArgs
*
rewrite_args
)
{
static
Box
*
binopInternalHelper
(
BinopRewriteArgs
*&
rewrite_args
,
BoxedString
*
op_name
,
Box
*
lhs
,
Box
*
rhs
,
RewriterVar
*
r_lhs
,
RewriterVar
*
r_rhs
)
{
if
(
rewritable
==
NOT_REWRITABLE
)
{
assert
(
!
rewrite_args
);
rewrite_args
=
NULL
;
}
// TODO handle the case of the rhs being a subclass of the lhs
// this could get really annoying because you can dynamically make one type a subclass
// of the other!
if
(
rewrite_args
)
{
// TODO probably don't need to guard on the lhs_cls since it
// will get checked no matter what, but the check that should be
// removed is probably the later one.
// ie we should have some way of specifying what we know about the values
// of objects and their attributes, and the attributes' attributes.
rewrite_args
->
lhs
->
addAttrGuard
(
offsetof
(
Box
,
cls
),
(
intptr_t
)
lhs
->
cls
);
rewrite_args
->
rhs
->
addAttrGuard
(
offsetof
(
Box
,
cls
),
(
intptr_t
)
rhs
->
cls
);
}
struct
NotImplementedHelper
{
static
void
call
(
Box
*
r
,
bool
was_notimplemented
)
{
assert
((
r
==
NotImplemented
)
==
was_notimplemented
);
}
};
Box
*
irtn
=
NULL
;
if
(
inplace
)
{
// XXX I think we need to make sure that we keep these strings alive?
DecrefHandle
<
BoxedString
>
iop_name
(
getInplaceOpName
(
op_type
));
if
(
rewrite_args
)
{
CallattrRewriteArgs
srewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
lhs
,
rewrite_args
->
destination
);
srewrite_args
.
arg1
=
rewrite_args
->
rhs
;
srewrite_args
.
args_guarded
=
true
;
irtn
=
callattrInternal1
<
CXX
,
REWRITABLE
>
(
lhs
,
iop_name
,
CLASS_ONLY
,
&
srewrite_args
,
ArgPassSpec
(
1
),
rhs
);
if
(
!
srewrite_args
.
isSuccessful
())
{
rewrite_args
=
NULL
;
}
else
if
(
irtn
)
{
rewrite_args
->
out_rtn
=
srewrite_args
.
getReturn
(
ReturnConvention
::
HAS_RETURN
);
// If we allowed a rewrite to get here, it means that we assumed that the class will return NotImplemented
// or not based only on the types of the inputs.
#ifndef NDEBUG
rewrite_args
->
rewriter
->
call
(
false
,
(
void
*
)
NotImplementedHelper
::
call
,
rewrite_args
->
out_rtn
,
rewrite_args
->
rewriter
->
loadConst
(
irtn
==
NotImplemented
));
#endif
}
else
{
srewrite_args
.
assertReturnConvention
(
ReturnConvention
::
NO_RETURN
);
}
}
else
{
irtn
=
callattrInternal1
<
CXX
,
NOT_REWRITABLE
>
(
lhs
,
iop_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
rhs
);
}
if
(
irtn
)
{
if
(
irtn
!=
NotImplemented
)
{
if
(
rewrite_args
)
{
assert
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
return
irtn
;
}
else
{
Py_DECREF
(
irtn
);
assert
(
!
rewrite_args
);
}
}
}
BORROWED
(
BoxedString
*
)
op_name
=
getOpName
(
op_type
);
Box
*
lrtn
;
Box
*
rtn
=
NULL
;
if
(
rewrite_args
)
{
CallattrRewriteArgs
srewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
lhs
,
rewrite_args
->
destination
);
srewrite_args
.
arg1
=
rewrite_args
->
rhs
;
lrtn
=
callattrInternal1
<
CXX
,
REWRITABLE
>
(
lhs
,
op_name
,
CLASS_ONLY
,
&
srewrite_args
,
ArgPassSpec
(
1
),
rhs
);
CallattrRewriteArgs
srewrite_args
(
rewrite_args
->
rewriter
,
r_lhs
,
rewrite_args
->
destination
);
srewrite_args
.
arg1
=
r_rhs
;
srewrite_args
.
args_guarded
=
true
;
rtn
=
callattrInternal1
<
CXX
,
REWRITABLE
>
(
lhs
,
op_name
,
CLASS_ONLY
,
&
srewrite_args
,
ArgPassSpec
(
1
),
rhs
);
if
(
!
srewrite_args
.
isSuccessful
())
{
rewrite_args
=
NULL
;
}
else
if
(
l
rtn
)
{
}
else
if
(
rtn
)
{
rewrite_args
->
out_rtn
=
srewrite_args
.
getReturn
(
ReturnConvention
::
HAS_RETURN
);
// If we allowed a rewrite to get here, it means that we assumed that the class will return NotImplemented
// or not based only on the types of the inputs.
#ifndef NDEBUG
rewrite_args
->
rewriter
->
call
(
false
,
(
void
*
)
NotImplementedHelper
::
call
,
rewrite_args
->
out_rtn
,
rewrite_args
->
rewriter
->
loadConst
(
i
rtn
==
NotImplemented
));
rewrite_args
->
rewriter
->
loadConst
(
rtn
==
NotImplemented
));
#endif
}
else
{
srewrite_args
.
assertReturnConvention
(
ReturnConvention
::
NO_RETURN
);
}
}
else
{
lrtn
=
callattrInternal1
<
CXX
,
NOT_REWRITABLE
>
(
lhs
,
op_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
rhs
);
}
if
(
lrtn
)
{
if
(
lrtn
!=
NotImplemented
)
{
if
(
rewrite_args
)
{
assert
(
rewrite_args
->
out_rtn
);
if
(
rewrite_args
&&
rtn
)
{
if
(
rtn
!=
NotImplemented
)
rewrite_args
->
out_success
=
true
;
else
{
// I think our guarding up to here is correct; the issue is we won't be able to complete
// the rewrite since we have more guards to do, but we already did some mutations.
rewrite_args
->
out_success
=
false
;
rewrite_args
=
NULL
;
REWRITE_ABORTED
(
""
);
}
return
lrtn
;
}
Py_DECREF
(
lrtn
);
// we don't need to abort the rewrite when the attribute does not exist (rtn==null) because we only rewrite
// binops when both sides are not user defined types for which we assume that they will never change.
}
else
{
rtn
=
callattrInternal1
<
CXX
,
NOT_REWRITABLE
>
(
lhs
,
op_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
rhs
);
}
// TODO patch these cases
// I think our guarding up to here is correct; the issue is we won't be able to complete
// the rewrite since we have more guards to do, but we already did some mutations.
if
(
rewrite_args
)
{
assert
(
rewrite_args
->
out_success
==
false
);
return
rtn
;
}
template
<
Rewritable
rewritable
>
Box
*
binopInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
bool
inplace
,
BinopRewriteArgs
*
rewrite_args
)
{
if
(
rewritable
==
NOT_REWRITABLE
)
{
assert
(
!
rewrite_args
);
rewrite_args
=
NULL
;
REWRITE_ABORTED
(
""
);
}
BoxedString
*
rop_name
=
getReverseOpName
(
op_type
);
AUTO_DECREF
(
rop_name
);
RewriterVar
*
r_lhs
=
NULL
;
RewriterVar
*
r_rhs
=
NULL
;
if
(
rewrite_args
)
{
r_lhs
=
rewrite_args
->
lhs
;
r_rhs
=
rewrite_args
->
rhs
;
Box
*
rrtn
=
callattrInternal1
<
CXX
,
REWRITABLE
>
(
rhs
,
rop_name
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
1
),
lhs
);
if
(
rrtn
!=
NULL
&&
rrtn
!=
NotImplemented
)
return
rrtn
;
Py_XDECREF
(
rrtn
);
RewriterVar
*
r_lhs_cls
=
r_lhs
->
getAttr
(
offsetof
(
Box
,
cls
))
->
setType
(
RefType
::
BORROWED
);
r_lhs_cls
->
addGuard
((
intptr_t
)
lhs
->
cls
);
RewriterVar
*
r_rhs_cls
=
r_rhs
->
getAttr
(
offsetof
(
Box
,
cls
))
->
setType
(
RefType
::
BORROWED
)
;
r_rhs_cls
->
addGuard
((
intptr_t
)
rhs
->
cls
);
r_lhs_cls
->
addAttrGuard
(
offsetof
(
BoxedClass
,
tp_mro
),
(
intptr_t
)
lhs
->
cls
->
tp_mro
);
r_rhs_cls
->
addAttrGuard
(
offsetof
(
BoxedClass
,
tp_mro
),
(
intptr_t
)
rhs
->
cls
->
tp_mro
);
}
llvm
::
StringRef
op_sym
=
getOpSymbol
(
op_type
);
const
char
*
op_sym_suffix
=
""
;
if
(
inplace
)
{
op_sym_suffix
=
"="
;
// XXX I think we need to make sure that we keep these strings alive?
DecrefHandle
<
BoxedString
>
iop_name
=
getInplaceOpName
(
op_type
);
Box
*
irtn
=
binopInternalHelper
<
rewritable
>
(
rewrite_args
,
iop_name
,
lhs
,
rhs
,
r_lhs
,
r_rhs
);
if
(
irtn
)
{
if
(
irtn
!=
NotImplemented
)
return
irtn
;
Py_DECREF
(
irtn
);
}
}
if
(
VERBOSITY
())
{
if
(
inplace
)
{
BoxedString
*
iop_name
=
getInplaceOpName
(
op_type
);
if
(
irtn
)
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
lhs
),
iop_name
->
c_str
());
else
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
lhs
),
iop_name
->
c_str
());
bool
should_try_reverse
=
true
;
if
(
lhs
->
cls
!=
rhs
->
cls
&&
isSubclass
(
rhs
->
cls
,
lhs
->
cls
))
{
should_try_reverse
=
false
;
DecrefHandle
<
BoxedString
>
rop_name
=
getReverseOpName
(
op_type
);
Box
*
rrtn
=
binopInternalHelper
<
rewritable
>
(
rewrite_args
,
rop_name
,
rhs
,
lhs
,
r_rhs
,
r_lhs
);
if
(
rrtn
)
{
if
(
rrtn
!=
NotImplemented
)
return
rrtn
;
Py_DECREF
(
rrtn
);
}
}
if
(
lrtn
)
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
lhs
),
op_name
->
c_str
());
else
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
lhs
),
op_name
->
c_str
());
if
(
rrtn
)
fprintf
(
stderr
,
"%s has %s, but returned NotImplemented
\n
"
,
getTypeName
(
rhs
),
rop_name
->
c_str
());
else
fprintf
(
stderr
,
"%s does not have %s
\n
"
,
getTypeName
(
rhs
),
rop_name
->
c_str
());
BORROWED
(
BoxedString
*
)
op_name
=
getOpName
(
op_type
);
Box
*
lrtn
=
binopInternalHelper
<
rewritable
>
(
rewrite_args
,
op_name
,
lhs
,
rhs
,
r_lhs
,
r_rhs
);
if
(
lrtn
)
{
if
(
lrtn
!=
NotImplemented
)
return
lrtn
;
Py_DECREF
(
lrtn
);
}
if
(
should_try_reverse
)
{
DecrefHandle
<
BoxedString
>
rop_name
=
getReverseOpName
(
op_type
);
Box
*
rrtn
=
binopInternalHelper
<
rewritable
>
(
rewrite_args
,
rop_name
,
rhs
,
lhs
,
r_rhs
,
r_lhs
);
if
(
rrtn
)
{
if
(
rrtn
!=
NotImplemented
)
return
rrtn
;
Py_DECREF
(
rrtn
);
}
}
llvm
::
StringRef
op_sym
=
getOpSymbol
(
op_type
);
const
char
*
op_sym_suffix
=
""
;
if
(
inplace
)
{
op_sym_suffix
=
"="
;
}
raiseExcHelper
(
TypeError
,
"unsupported operand type(s) for %s%s: '%s' and '%s'"
,
op_sym
.
data
(),
op_sym_suffix
,
...
...
test/tests/binops_subclass.py
View file @
6c22df2f
# expected: fail
# - binop ordering is wrong,
# should prefer executing a operation on the subclass first
class
M
(
type
):
def
__instancecheck__
(
self
,
rhs
):
print
"M.instancecheck"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment