{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1447","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1447/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1447/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1447/events","html_url":"https://github.com/dotnet/csharplang/issues/1447","id":312437402,"node_id":"MDU6SXNzdWUzMTI0Mzc0MDI=","number":1447,"title":"Proposal: Customisable overload resolution ","user":{"login":"popcatalin81","id":1791839,"node_id":"MDQ6VXNlcjE3OTE4Mzk=","avatar_url":"https://avatars3.githubusercontent.com/u/1791839?v=4","gravatar_id":"","url":"https://api.github.com/users/popcatalin81","html_url":"https://github.com/popcatalin81","followers_url":"https://api.github.com/users/popcatalin81/followers","following_url":"https://api.github.com/users/popcatalin81/following{/other_user}","gists_url":"https://api.github.com/users/popcatalin81/gists{/gist_id}","starred_url":"https://api.github.com/users/popcatalin81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/popcatalin81/subscriptions","organizations_url":"https://api.github.com/users/popcatalin81/orgs","repos_url":"https://api.github.com/users/popcatalin81/repos","events_url":"https://api.github.com/users/popcatalin81/events{/privacy}","received_events_url":"https://api.github.com/users/popcatalin81/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":42,"created_at":"2018-04-09T08:23:08Z","updated_at":"2018-08-09T18:37:00Z","closed_at":null,"author_association":"NONE","body":"## Customisable overload resolution \r\n\r\nThis is a proposal to add a customization mechanism for the C# language, to control method group overload resolution.\r\n\r\n## Summary:\r\n\r\nC# overload resolution is designed for best possible backward compatibility in the general case. Some special types of libraries and evolving APIs meet some difficulties in implementation when their needs diverge from the C# language rules. IE: instead of being focused on compatibility they are focused on performance or improved functionality :\r\n\r\n## Motivation:\r\n\r\n- API evolution: Allow library writers more control over overload resolution in API evolving scenarios like migration from non-generic to generic, or from string to FormattableString APIs. \r\n- Performance work: Allow library writers to chose nonboxing conversion overloads over boxing overloads.\r\n\r\n## Design\r\n\r\n - Define a new a new `[PreferredOverloadAttribute]` to designate higher priority method overloads from a valid method group. \r\n- The attribute will have a `PriorityBoost` integer property to allow specifying different priorities for valid candidate methods. \r\n- For methods with the same `PriorityBoost` value, the regular overload resolution rules will apply. \r\n\r\n# Formattable string example:\r\n\r\n```CSharp\r\nclass Program {\r\n\tstatic void Main()\r\n\t{\r\n\t\tWrite($\"Hello the date is  {DateTime.Now}\");\t\r\n\t}\r\n\tstatic void Write(string text)\r\n\t{\r\n\t\tConsole.WriteLine(\"unformated\");\r\n\t}\r\n\r\n        [PreferredOverload]\r\n\tstatic void Write(IFormattable text)\r\n\t{\r\n\t\tConsole.WriteLine(\"formatted\");\r\n\t}\r\n\r\n        [PreferredOverload(PriorityBoost = 2)]\r\n\tstatic void Write(FormattableString text)\r\n\t{\r\n\t\tConsole.WriteLine(\"formattable string\");\r\n\t}\r\n}\r\n```\r\nThis is a case where a structured Logging library will indicate the preference to use the formattable string overload over the string overload in order to enhance its API usage. \r\n\r\n**C# 7.2**:\r\n`unformatted`\r\n\r\n**C# 7.2+**:\r\n`formattable string`\r\n\r\n# ISpanFormattable example:\r\n\r\n```CSharp\r\nclass Program {\r\n\tstatic void Main()\r\n\t{\r\n\t\tWrite(1);\r\n\t}\r\n\t\r\n\tstatic void Write(object value)\r\n\t{\r\n\t\tConsole.WriteLine(\"object\");\r\n\t}\r\n\r\n\t[PreferredOverload]\r\n\tstatic void WriteT<T>(T value)\r\n\t\t\twhere T:ISpanFormattable\r\n\t{\r\n\t\tConsole.WriteLine(\"ISpanFormattable\");\r\n\t}\r\n}\r\n```\r\nThis will allow libraries to take advantage of newer performance oriented features  without introducing new method names that will require source changes, only recompilation with the latest compiler:\r\n\r\n**C# 7.2**:\r\n`object`\r\n\r\n**C# 7.2+**:\r\n`ISpanFormattable`\r\n\r\n# params Span&lt;T&gt; example\r\n\r\n\r\n```CSharp\r\n[PreferredOverload]\r\nvoid Foo(params Span<int> values);\r\n\r\nvoid Foo(params int[] values);\r\n```\r\nThis will allow method overload resolution to chose the `Span<T>` based overload instead of the `int[]` overload chossing the allocation free path,\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/411855442","html_url":"https://github.com/dotnet/csharplang/issues/1447#issuecomment-411855442","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1447","id":411855442,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTg1NTQ0Mg==","user":{"login":"jnm2","id":8040367,"node_id":"MDQ6VXNlcjgwNDAzNjc=","avatar_url":"https://avatars2.githubusercontent.com/u/8040367?v=4","gravatar_id":"","url":"https://api.github.com/users/jnm2","html_url":"https://github.com/jnm2","followers_url":"https://api.github.com/users/jnm2/followers","following_url":"https://api.github.com/users/jnm2/following{/other_user}","gists_url":"https://api.github.com/users/jnm2/gists{/gist_id}","starred_url":"https://api.github.com/users/jnm2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnm2/subscriptions","organizations_url":"https://api.github.com/users/jnm2/orgs","repos_url":"https://api.github.com/users/jnm2/repos","events_url":"https://api.github.com/users/jnm2/events{/privacy}","received_events_url":"https://api.github.com/users/jnm2/received_events","type":"User","site_admin":false},"created_at":"2018-08-09T18:37:00Z","updated_at":"2018-08-09T18:37:00Z","author_association":"CONTRIBUTOR","body":"@HaloFour I don't understand why it would be incompatible with newer compilers. I'd want a `params int[]` in case the langversion or compiler version is lower, and a `params Span<int>` which newer compilers would always pick instead."}}
{"actor":{"display_login":"jnm2"}}