{"action":"created","issue":{"url":"https://api.github.com/repos/apple/swift/issues/1075","repository_url":"https://api.github.com/repos/apple/swift","labels_url":"https://api.github.com/repos/apple/swift/issues/1075/labels{/name}","comments_url":"https://api.github.com/repos/apple/swift/issues/1075/comments","events_url":"https://api.github.com/repos/apple/swift/issues/1075/events","html_url":"https://github.com/apple/swift/pull/1075","id":128381717,"number":1075,"title":"[WIP][Sema] implement better type circularity check","user":{"login":"dduan","id":75067,"avatar_url":"https://avatars.githubusercontent.com/u/75067?v=3","gravatar_id":"","url":"https://api.github.com/users/dduan","html_url":"https://github.com/dduan","followers_url":"https://api.github.com/users/dduan/followers","following_url":"https://api.github.com/users/dduan/following{/other_user}","gists_url":"https://api.github.com/users/dduan/gists{/gist_id}","starred_url":"https://api.github.com/users/dduan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dduan/subscriptions","organizations_url":"https://api.github.com/users/dduan/orgs","repos_url":"https://api.github.com/users/dduan/repos","events_url":"https://api.github.com/users/dduan/events{/privacy}","received_events_url":"https://api.github.com/users/dduan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"slavapestov","id":66486,"avatar_url":"https://avatars.githubusercontent.com/u/66486?v=3","gravatar_id":"","url":"https://api.github.com/users/slavapestov","html_url":"https://github.com/slavapestov","followers_url":"https://api.github.com/users/slavapestov/followers","following_url":"https://api.github.com/users/slavapestov/following{/other_user}","gists_url":"https://api.github.com/users/slavapestov/gists{/gist_id}","starred_url":"https://api.github.com/users/slavapestov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slavapestov/subscriptions","organizations_url":"https://api.github.com/users/slavapestov/orgs","repos_url":"https://api.github.com/users/slavapestov/repos","events_url":"https://api.github.com/users/slavapestov/events{/privacy}","received_events_url":"https://api.github.com/users/slavapestov/received_events","type":"User","site_admin":false},"milestone":null,"comments":14,"created_at":"2016-01-24T08:37:17Z","updated_at":"2016-02-08T03:53:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/1075","html_url":"https://github.com/apple/swift/pull/1075","diff_url":"https://github.com/apple/swift/pull/1075.diff","patch_url":"https://github.com/apple/swift/pull/1075.patch"},"body":"This is a change based on @slavapestov's [comment here](https://github.com/apple/swift/pull/1011). \r\n\r\nCertain type circularities weren't being checked until this point. Such as\r\n\r\n```\r\nstruct X<T> { let a: X<X> }\r\nstruct Y<T> { let a: (Int, Y<Y>) }\r\nenum Z<T> { case A(Optional<Z<Z>>) }\r\n```\r\n\r\nWe introduce a more comprehensive approach to detect these in type checker.\r\nAfter name lookup, exam each value field in declared structs and enums for\r\nself-reference types that creates inifinite sizes.\r\n"},"comment":{"url":"https://api.github.com/repos/apple/swift/issues/comments/181184757","html_url":"https://github.com/apple/swift/pull/1075#issuecomment-181184757","issue_url":"https://api.github.com/repos/apple/swift/issues/1075","id":181184757,"user":{"login":"dduan","id":75067,"avatar_url":"https://avatars.githubusercontent.com/u/75067?v=3","gravatar_id":"","url":"https://api.github.com/users/dduan","html_url":"https://github.com/dduan","followers_url":"https://api.github.com/users/dduan/followers","following_url":"https://api.github.com/users/dduan/following{/other_user}","gists_url":"https://api.github.com/users/dduan/gists{/gist_id}","starred_url":"https://api.github.com/users/dduan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dduan/subscriptions","organizations_url":"https://api.github.com/users/dduan/orgs","repos_url":"https://api.github.com/users/dduan/repos","events_url":"https://api.github.com/users/dduan/events{/privacy}","received_events_url":"https://api.github.com/users/dduan/received_events","type":"User","site_admin":false},"created_at":"2016-02-08T03:53:03Z","updated_at":"2016-02-08T03:53:03Z","body":"@slavapestov Here's my understanding of how it works.\r\n\r\nSay we are checking `struct A { let s: S<Int> }`, what happens currently is:\r\n\r\n1. call `getDeclaredTypeInContext()` on `A`'s decl.\r\n2. call `getTypeOfMember()` on result of previous step, which should give us `S<Int>`.\r\n3. In `deconstructTypeForDeclCircularity()`, `S<Int>` and it's decl `S<T>` are passed to `checkNominalDeclCircularity()` in order to check `S`'s declaration with the substitute.\r\n4. This time, `getTypeOfMember()` IS called on `S<Int>` since `baseType` is not `nullptr`.\r\n\r\nThis way `check(Struct | Enum)DeclCircularity` works on both generic and non-generic nominal types.\r\n\r\nWhat did I miss? All tests are passing BTW."}}