I'm working on SR-4464 to learn how to contribute to Swift. I think I
have the solution, but I'm getting unexpected results.
I'm using the swift repl within Xcode for testing. Here's my test code.
var name = "name"
name = (name)
In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
*. Could someone help me figure out what's happening?
Hi, Halen. Welcome to the compiler. :-) What you're seeing is that we don't usually use C++'s normal RTTI <https://en.wikipedia.org/wiki/Run-time_type_information> mechanism, but instead go with a "Kind" field that's checked by the custom 'cast', 'dyn_cast', and 'isa' functions. (More information in the LLVM Programmer's Manual <LLVM Programmer’s Manual — LLVM 18.0.0git documentation) The debugger doesn't know about this, so it just always shows the base class to be conservative. If you're debugging, you can call dump() to see what kind of Expr it really is, and then cast the pointer down to the right type as needed. In your actual code, you can check `isa<ParenExpr>(src)`, or `dyn_cast<ParenExpr>(src)` if you then need to manipulate the ParenExpr.
Hope that helps,
Jordan
···
On Apr 6, 2017, at 15:30, Halen Wooten via swift-dev <swift-dev@swift.org> wrote:
Hi swift devs,
I'm working on SR-4464 to learn how to contribute to Swift. I think I
have the solution, but I'm getting unexpected results.
I'm using the swift repl within Xcode for testing. Here's my test code.
var name = "name"
name = (name)
In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
*. Could someone help me figure out what's happening?
auto src = AE->getSrc();
auto parenSrc = dyn_cast<ParenExpr>(src);
if (parenSrc)
return false;
...
}
···
On Thu, Apr 6, 2017 at 6:49 PM, Jordan Rose <jordan_rose@apple.com> wrote:
Hi, Halen. Welcome to the compiler. :-) What you're seeing is that we don't
usually use C++'s normal RTTI mechanism, but instead go with a "Kind" field
that's checked by the custom 'cast', 'dyn_cast', and 'isa' functions. (More
information in the LLVM Programmer's Manual.) The debugger doesn't know
about this, so it just always shows the base class to be conservative. If
you're debugging, you can call dump() to see what kind of Expr it really is,
and then cast the pointer down to the right type as needed. In your actual
code, you can check `isa<ParenExpr>(src)`, or `dyn_cast<ParenExpr>(src)` if
you then need to manipulate the ParenExpr.
Hope that helps,
Jordan
On Apr 6, 2017, at 15:30, Halen Wooten via swift-dev <swift-dev@swift.org> > wrote:
Hi swift devs,
I'm working on SR-4464 to learn how to contribute to Swift. I think I
have the solution, but I'm getting unexpected results.
I'm using the swift repl within Xcode for testing. Here's my test code.
var name = "name"
name = (name)
In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
*. Could someone help me figure out what's happening?
Here’s what the AST looks like in this case — there is a ParenExpr but it’s inside a LoadExpr — we’re semantically loading the largest sub-expression that’s an lvalue, which here is ‘(x)’ not ‘x’:
auto src = AE->getSrc();
auto parenSrc = dyn_cast<ParenExpr>(src);
if (parenSrc)
return false;
...
}
On Thu, Apr 6, 2017 at 6:49 PM, Jordan Rose <jordan_rose@apple.com> wrote:
Hi, Halen. Welcome to the compiler. :-) What you're seeing is that we don't
usually use C++'s normal RTTI mechanism, but instead go with a "Kind" field
that's checked by the custom 'cast', 'dyn_cast', and 'isa' functions. (More
information in the LLVM Programmer's Manual.) The debugger doesn't know
about this, so it just always shows the base class to be conservative. If
you're debugging, you can call dump() to see what kind of Expr it really is,
and then cast the pointer down to the right type as needed. In your actual
code, you can check `isa<ParenExpr>(src)`, or `dyn_cast<ParenExpr>(src)` if
you then need to manipulate the ParenExpr.
Hope that helps,
Jordan
On Apr 6, 2017, at 15:30, Halen Wooten via swift-dev <swift-dev@swift.org> >> wrote:
Hi swift devs,
I'm working on SR-4464 to learn how to contribute to Swift. I think I
have the solution, but I'm getting unexpected results.
I'm using the swift repl within Xcode for testing. Here's my test code.
var name = "name"
name = (name)
In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
*. Could someone help me figure out what's happening?
Thanks so much to you both for helping out. Hopefully I'll have a PR
ready before too long!
···
On Thu, Apr 6, 2017 at 7:11 PM, Halen Wooten <halen@hpwooten.com> wrote:
Ah, that makes sense.
Thanks so much to you both for helping out. Hopefully I'll have a PR
ready before too long!
Halen
On Thu, Apr 6, 2017 at 7:05 PM, Slava Pestov <spestov@apple.com> wrote:
Here’s what the AST looks like in this case — there is a ParenExpr but it’s inside a LoadExpr — we’re semantically loading the largest sub-expression that’s an lvalue, which here is ‘(x)’ not ‘x’:
auto src = AE->getSrc();
auto parenSrc = dyn_cast<ParenExpr>(src);
if (parenSrc)
return false;
...
}
On Thu, Apr 6, 2017 at 6:49 PM, Jordan Rose <jordan_rose@apple.com> wrote:
Hi, Halen. Welcome to the compiler. :-) What you're seeing is that we don't
usually use C++'s normal RTTI mechanism, but instead go with a "Kind" field
that's checked by the custom 'cast', 'dyn_cast', and 'isa' functions. (More
information in the LLVM Programmer's Manual.) The debugger doesn't know
about this, so it just always shows the base class to be conservative. If
you're debugging, you can call dump() to see what kind of Expr it really is,
and then cast the pointer down to the right type as needed. In your actual
code, you can check `isa<ParenExpr>(src)`, or `dyn_cast<ParenExpr>(src)` if
you then need to manipulate the ParenExpr.
Hope that helps,
Jordan
On Apr 6, 2017, at 15:30, Halen Wooten via swift-dev <swift-dev@swift.org> >>>> wrote:
Hi swift devs,
I'm working on SR-4464 to learn how to contribute to Swift. I think I
have the solution, but I'm getting unexpected results.
I'm using the swift repl within Xcode for testing. Here's my test code.
var name = "name"
name = (name)
In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
*. Could someone help me figure out what's happening?