{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/15437","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/15437/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/15437/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/15437/events","html_url":"https://github.com/dotnet/roslyn/issues/15437","id":190874391,"number":15437,"title":"Optimize lowering of discard in pattern to not introduce local","user":{"login":"jcouv","id":12466233,"avatar_url":"https://avatars.githubusercontent.com/u/12466233?v=3","gravatar_id":"","url":"https://api.github.com/users/jcouv","html_url":"https://github.com/jcouv","followers_url":"https://api.github.com/users/jcouv/followers","following_url":"https://api.github.com/users/jcouv/following{/other_user}","gists_url":"https://api.github.com/users/jcouv/gists{/gist_id}","starred_url":"https://api.github.com/users/jcouv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcouv/subscriptions","organizations_url":"https://api.github.com/users/jcouv/orgs","repos_url":"https://api.github.com/users/jcouv/repos","events_url":"https://api.github.com/users/jcouv/events{/privacy}","received_events_url":"https://api.github.com/users/jcouv/received_events","type":"User","site_admin":false},"labels":[{"id":166673288,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7","default":false},{"id":332342663,"url":"https://api.github.com/repos/dotnet/roslyn/labels/New%20Language%20Feature%20-%20Tuples","name":"New Language Feature - Tuples","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":{"login":"jcouv","id":12466233,"avatar_url":"https://avatars.githubusercontent.com/u/12466233?v=3","gravatar_id":"","url":"https://api.github.com/users/jcouv","html_url":"https://github.com/jcouv","followers_url":"https://api.github.com/users/jcouv/followers","following_url":"https://api.github.com/users/jcouv/following{/other_user}","gists_url":"https://api.github.com/users/jcouv/gists{/gist_id}","starred_url":"https://api.github.com/users/jcouv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcouv/subscriptions","organizations_url":"https://api.github.com/users/jcouv/orgs","repos_url":"https://api.github.com/users/jcouv/repos","events_url":"https://api.github.com/users/jcouv/events{/privacy}","received_events_url":"https://api.github.com/users/jcouv/received_events","type":"User","site_admin":false},"assignees":[{"login":"jcouv","id":12466233,"avatar_url":"https://avatars.githubusercontent.com/u/12466233?v=3","gravatar_id":"","url":"https://api.github.com/users/jcouv","html_url":"https://github.com/jcouv","followers_url":"https://api.github.com/users/jcouv/followers","following_url":"https://api.github.com/users/jcouv/following{/other_user}","gists_url":"https://api.github.com/users/jcouv/gists{/gist_id}","starred_url":"https://api.github.com/users/jcouv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcouv/subscriptions","organizations_url":"https://api.github.com/users/jcouv/orgs","repos_url":"https://api.github.com/users/jcouv/repos","events_url":"https://api.github.com/users/jcouv/events{/privacy}","received_events_url":"https://api.github.com/users/jcouv/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/25","html_url":"https://github.com/dotnet/roslyn/milestones/2.0%20(RC.3)","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/25/labels","id":2090736,"number":25,"title":"2.0 (RC.3)","description":"","creator":{"login":"jaredpar","id":146967,"avatar_url":"https://avatars.githubusercontent.com/u/146967?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredpar","html_url":"https://github.com/jaredpar","followers_url":"https://api.github.com/users/jaredpar/followers","following_url":"https://api.github.com/users/jaredpar/following{/other_user}","gists_url":"https://api.github.com/users/jaredpar/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredpar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredpar/subscriptions","organizations_url":"https://api.github.com/users/jaredpar/orgs","repos_url":"https://api.github.com/users/jaredpar/repos","events_url":"https://api.github.com/users/jaredpar/events{/privacy}","received_events_url":"https://api.github.com/users/jaredpar/received_events","type":"User","site_admin":false},"open_issues":53,"closed_issues":10,"state":"open","created_at":"2016-10-24T21:54:30Z","updated_at":"2016-11-22T00:21:57Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2016-11-22T00:21:57Z","updated_at":"2016-11-22T00:21:57Z","closed_at":null,"body":"Feedback from https://github.com/dotnet/roslyn/pull/15192#discussion_r88987475\r\n\r\nIn the code below, instead of making a local, we can move the discard handling logic down into `MakeIsDeclarationPattern` to use `MakeStaticAssignmentOperator` instead of `_factory.AssignmentExpression`.\r\n\r\n```C#\r\n        private BoundExpression MakeIsDeclarationPattern(BoundDeclarationPattern loweredPattern, BoundExpression loweredInput)\r\n        {\r\n            Debug.Assert(((object)loweredPattern.Variable == null && loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression) ||\r\n                         loweredPattern.Variable.GetTypeOrReturnType() == loweredPattern.DeclaredType.Type);\r\n\r\n            if (loweredPattern.IsVar)\r\n            {\r\n                var result = _factory.Literal(true);\r\n\r\n                if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression)\r\n                {\r\n                    return result;\r\n                }\r\n\r\n                Debug.Assert((object)loweredPattern.Variable != null && loweredInput.Type == loweredPattern.Variable.GetTypeOrReturnType());\r\n\r\n                var assignment = _factory.AssignmentExpression(loweredPattern.VariableAccess, loweredInput);\r\n                return _factory.MakeSequence(assignment, result);\r\n            }\r\n\r\n            if (loweredPattern.VariableAccess.Kind == BoundKind.DiscardedExpression)\r\n            {\r\n                LocalSymbol temp;\r\n                BoundLocal discard = _factory.MakeTempForDiscard((BoundDiscardedExpression)loweredPattern.VariableAccess, out temp);\r\n\r\n                return _factory.Sequence(ImmutableArray.Create(temp),\r\n                         sideEffects: ImmutableArray<BoundExpression>.Empty,\r\n                         result: MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, discard, requiresNullTest: true));\r\n            }\r\n\r\n            return MakeIsDeclarationPattern(loweredPattern.Syntax, loweredInput, loweredPattern.VariableAccess, requiresNullTest: true); // handle discards in here instead\r\n        }\r\n```"}}
{"actor":{"display_login":"jcouv"}}