Skip to content
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

Ref returns/locals: Crash (& Debug.Asserts) in Inline Temp #8416

Closed
dpoeschl opened this issue Feb 5, 2016 · 13 comments
Closed

Ref returns/locals: Crash (& Debug.Asserts) in Inline Temp #8416

dpoeschl opened this issue Feb 5, 2016 · 13 comments
Assignees
Milestone

Comments

@dpoeschl
Copy link
Contributor

dpoeschl commented Feb 5, 2016

  1. Paste C#:

    class C
    {
        ref int M()
        {
            int[] arr = new[] { 1, 2, 3 };
            ref int x = ref arr[2];
            return ref x;
        }
    }
  2. Try to inline temp on x

Crash:

    Microsoft.CodeAnalysis.CSharp.Features.dll!Microsoft.CodeAnalysis.CSharp.CodeRefactorings.InlineTemporary.InlineTemporaryCodeRefactoringProvider.DetectSemanticConflicts(Microsoft.CodeAnalysis.Document inlinedDocument, Microsoft.CodeAnalysis.SemanticModel newSemanticModelForInlinedDocument, Microsoft.CodeAnalysis.SemanticModel semanticModelBeforeInline, Microsoft.CodeAnalysis.SymbolInfo originalInitializerSymbolInfo, System.Threading.CancellationToken cancellationToken) Line 519  C#
    Microsoft.CodeAnalysis.CSharp.Features.dll!Microsoft.CodeAnalysis.CSharp.CodeRefactorings.InlineTemporary.InlineTemporaryCodeRefactoringProvider.InlineTemporaryAsync(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDeclaratorSyntax declarator, System.Threading.CancellationToken cancellationToken) Line 227    C#
@dpoeschl dpoeschl added this to the 2.0 milestone Feb 5, 2016
@dpoeschl
Copy link
Contributor Author

dpoeschl commented Feb 5, 2016

@jaredpar @Pilchie Labeling & assigning as requested, but do you want different labeling for IDE failures?

@jaredpar
Copy link
Member

jaredpar commented Feb 5, 2016

I'd label compiler / IDE as if this were a bug we discovered in the working product. Should keep that consistent. Can make a separate decision later on which bugs are fixed by who.

My 2 cents.

@dpoeschl dpoeschl removed this from the 2.0 milestone Feb 5, 2016
@Pilchie Pilchie modified the milestone: 2.0 Feb 8, 2016
@DustinCampbell DustinCampbell added this to the 1.2 milestone Feb 9, 2016
@DustinCampbell DustinCampbell self-assigned this Feb 9, 2016
@DustinCampbell DustinCampbell modified the milestones: 2.0 (Preview), 1.2 Feb 9, 2016
@dpoeschl dpoeschl added the Feature - Ref Locals and Returns Ref Locals and Returns label Feb 11, 2016
@dpoeschl
Copy link
Contributor Author

@jaredpar @DustinCampbell @Pilchie What's the plan for this? Should this block merging (both in theory and in practice -- I'm okay with different answers for those since this is our first rodeo)?

@Pilchie
Copy link
Member

Pilchie commented Feb 18, 2016

Our stated principle is that it's okay if refactorings around new language features don't work, but they shouldn't crash.

@dpoeschl
Copy link
Contributor Author

Is that also our "in practice" answer for this case?

Also, I think we need a way to mark these New Language Feature issues as Blocking or not, so when you look at the feature's issue query it's clear what's left to be done before merge. Maybe "Blocking Merge" or something?

@jaredpar
Copy link
Member

How about we create a milestone for this: Feature RI. Move blocking bugs into that milestone.

@Pilchie
Copy link
Member

Pilchie commented Feb 18, 2016

If this is the only crash, I'd probably be willing to bend the rules in this case. If there are a bunch of similar cases, I would worry about the experience we're shipping.

If only we had a label to know which issues would block the merge...

@dpoeschl dpoeschl modified the milestones: Language Feature Merging, 2.0 (Preview) Feb 18, 2016
@dpoeschl
Copy link
Contributor Author

@jaredpar That works for me. Optimistically added a "Language Feature Merging" milestone and added this to it. https://github.com/dotnet/roslyn/milestones/Language%20Feature%20Merging

Didn't want to have to explain what "RI" meant, and wanted to be clear that it was for "Language Features", not just general features... but maybe it should be for general features? Luckily Milestones are easily renamed :)

VSadov added a commit to VSadov/roslyn that referenced this issue Feb 19, 2016
The feature needs to be properly implemented taking into account that variable is byref.
For now disabling this refactoring if variable happen to be byref to avoid crash as described in dotnet#8416
@VSadov
Copy link
Member

VSadov commented Feb 19, 2016

I have added a workaround for the crash. For now the "inline temp" will not be permitted if a local happens to be byref, so there is no crash.

It seems that even in the absence of the crash the "inline temp" might not always do the right thing since it tries to add casts at use sites (expecting that most will be reduced) and that could cause compile errors in transformed code.

@jaredpar jaredpar added this to the 2.0 (Preview) milestone Feb 19, 2016
@jaredpar jaredpar removed this from the Language Feature Merging milestone Feb 19, 2016
@jaredpar
Copy link
Member

Nice! Given that it's not crashing anymore I'll move this out of the blocking bucket.

@dpoeschl
Copy link
Contributor Author

Expressions in ref contexts can't be expanded in certain ways (casting the outermost expression is illegal, but fully qualifying names is okay), so we'll need to update the simplification engine to take the target context into account. /cc: @DustinCampbell

@DustinCampbell
Copy link
Member

This shouldn't be a big deal. We should just update the expander to not add illegal expressions in those contexts. That's what we've done in the past.

@DustinCampbell DustinCampbell modified the milestones: 2.0 (RC), 2.0 (Preview) Mar 9, 2016
@jaredpar jaredpar modified the milestones: 2.0 (RC), 2.0 (RTM) Jul 18, 2016
@Pilchie Pilchie modified the milestones: 3.0, 2.0 (RTM) Jan 19, 2017
@jinujoseph jinujoseph modified the milestones: 16.0, 16.1 Jan 18, 2019
@jinujoseph jinujoseph modified the milestones: 16.1, Backlog Apr 24, 2019
@CyrusNajmabadi
Copy link
Member

This does not repro for me.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
@dotnet dotnet locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants