-
Notifications
You must be signed in to change notification settings - Fork 394
Initializer lists #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initializer lists #838
Conversation
|
Hi, sorry if I merged things in the wrong order, but it appears that this initializer list patch conflicts with some of the changes you made (that I've already merged) about how to score and resolve function polymorphism. There's a conflict in ASTfunction_call::typecheck, at least. Can you take a look, rebase this on current master, fix any conflicts, and update the PR? I like the idea of this, but want to make sure I'm testing properly including how it interacts with that other set of changes. |
e6ecd5e to
7df5bc7
Compare
|
Gonna resolve this and rebase to validate on Windows. |
|
So a new class of ambiguity now arrises. I would think this is too ambiguous and erroring might be wise? Consider ambiguity via init-list an error or put user structs at the end of the rules for selection, so |
|
Eew, too confusing, looks like an invitation for bugs. Let's issue an error for this kind of ambiguity. |
|
Are you thinking erring for all three ambiguities presented? I.e. should Is there a test case/snippet for the changes to ASTtype_constructor::typecheck you pushed in? |
|
I'm tempted to consider it an error (we can't "break" anything, since we didn't support {} constructors before at all). Then if people tell us that it's too strict, we can think about rank+warn like we do for function arguments. Re: type_constructor... are you asking for an explanation of what I changed, or an OSL test case that shows the case that it applies to? |
|
Shame I think I get what changed, but would like an explicit example beyond Just to verify mucking around in |
|
I'll add a testsuite case that verifies the type constructor fix. Noise is an interesting case. It is tempting to want noise({x,y,z}) to work, but it's only because we know that noise(point) and noise(vector) are identical implementations. So it works for noise, but in the general case where you had func(structA) and func(structB) that were different, but A and B could each have the same initializer list form, it seems like it would be ripe for errors. I'm not entirely convinced that noise{{3,2,1},0) is really a lot better than noise(point(3,2,1),0), or at least not enough to be worth grappling with a general solution to ambiguous cases. But if people really really didn't like having to write (and all its varieties) Dunno if that's solving any real problems for people, or if it's just rearranging deck chairs. |
Agree, but in more complicated cases (like color4 or worse) avoiding nested constructor calls is nice. Part of resolving this has shown two important cases overlooked in #844 that are currently present in master. To me it seems return candidates precedence should be either: When ambiguity is being resolved via return type, always error if more than one overload returns a user struct. |
|
I prefer your first precedence list -- structs should be lower priority than built-in types, I believe. And I agree that it should be an error for multiple possible overloads are user structs. I don't see any way to definitively rank user structs except by declaration order, which is what we're striving to avoid. |
|
Do a separate PR for this or just a single commit in this one that can be cherry-picked? Hopefully the last un-defined case is closures, do they have a higher or lower priority than the type they wrap? FWIW, the only reason I saw of structs being highest is so explicit casting an overloaded builtin isn't necessary. |
|
Separate PR -- either way is ok. Since the initializer notation is new, and it'll take at least several days after merging before even the people using master regularly are using it in earnest, I think it's ok to get the 90% solution in first, and then have a follow-up PR in the next few days that handles the tricky edge cases. closures -- gee, I have no idea. Make your best guess. I don't have a preference at this time. I suspect that there will be very few practical cases where this turns up. You can't typecast a non-closure to a closure, so it won't be an issue of function argument ambiguity. It can only be an issue if there are polymorphic functions that can return either closures or non-closures for the same argument list. Seems like an extreme edge case, and if we see that the strategy we choose is tripping people up, we can change it. (Remember, 'master' is subject to change in the rules until it becomes a release branch). |
dfa8cba to
5075ef8
Compare
|
Updated & includes #858 for my sanity later. |
Everything now flows properly through ASTcompound_initializer.
Hide some implementation details that don't need to be public.
5075ef8 to
fcbdb6c
Compare
|
I think LGTM and passes all my tests. There are some stylistic fixups I'm tempted to make, but I think I'll just do that myself as a separate PR. |
Description
Allows C++11 style initializer list syntax.
Uses type information available at compile time to fill in proper types for variables, function arguments, and return values.
Makes ASTcompound_initializer a subclass of ASTtype_constructor so it can use it's
codegenandtypecheckmethods.Tests
testsuite/initlist
testsuite/oslc-err-initlist-args
testsuite/oslc-err-initlist-return
testsuite/array-aassign
Checklist: