Skip to content

Resilience diagnostics #6669

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

Merged
merged 3 commits into from
Jan 10, 2017

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jan 9, 2017

rdar://problem/29164469
rdar://problem/23522157

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 16631b7b8c82e7e8ade183e1166b7c7588f802c4
Test requested by - @slavapestov

@slavapestov slavapestov force-pushed the resilience-diagnostics branch from 16631b7 to 04c52ed Compare January 9, 2017 08:44
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

2 similar comments
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 04c52edbdb0fc7e609354e726d840944707260c1
Test requested by - @slavapestov

@slavapestov
Copy link
Contributor Author

@swift-ci Please test macOS

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 04c52edbdb0fc7e609354e726d840944707260c1
Test requested by - @slavapestov

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 04c52edbdb0fc7e609354e726d840944707260c1
Test requested by - @slavapestov

slavapestov added a commit to slavapestov/swift-corelibs-foundation that referenced this pull request Jan 9, 2017
Referencing private or internal declarations from an @inline(__always)
body can lead to SIL verifier and linker failures, so now we diagnose
and prohibit it.

Mark the entity in question public, or if it is not part of user-visible
API, internal and @_versioned.

See <swiftlang/swift#6669>.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 04c52edbdb0fc7e609354e726d840944707260c1
Test requested by - @slavapestov

@slavapestov slavapestov force-pushed the resilience-diagnostics branch 2 times, most recently from eb103c9 to a46e17a Compare January 9, 2017 09:43
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 04c52edbdb0fc7e609354e726d840944707260c1
Test requested by - @slavapestov

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - a46e17aaf370ab8a978d5a0221e472c82aa9be3a
Test requested by - @slavapestov

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see diagnostics coming in! I'm a little uncomfortable to see this being defined in terms of ResilienceExpansion, though. I maintain that we're going to need AvailabilityContext as soon as we have versioned attributes, and I'd rather see ResilienceExpansion squashed and rebuilt from scratched than extended to match our current resilience model. (…because I don't feel like there is a natural way to do such an extension.)

};

/// If the body is able to be inlined into functions in other resilience
/// domains, this ensures that only sufficiently-conservative access patterns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: "access patterns" isn't a Sema-level term.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed the comment since it got copy-pasted from getResilienceExpansion() on accident.

@@ -4,18 +4,6 @@
// RUN: %target-swift-frontend -O -primary-file %s %S/Inputs/devirt_access_helper.swift -I %t -emit-sil -sil-inline-threshold 1000 -sil-verify-all | %FileCheck -check-prefix=WHOLE-MODULE %s
// RUN: %target-swift-frontend -O -primary-file %s %S/Inputs/devirt_access_helper.swift -I %t -emit-sil -sil-inline-threshold 1000 -sil-verify-all | %FileCheck -check-prefix=PRIMARY-FILE %s

import devirt_access_other_module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to just delete part of the test. Maybe run it under explicit non-resilient mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "explicit non-resilient" mode would just disable the new diagnostics. I'd be OK with making them conditional if we really had to, but I think basically this test was just exercising that the SIL optimizer doesn't blow up in a case that no longer type checks.

(DeclName, unsigned))

ERROR(resilience_decl_unavailable,
none, "%0 %1 is %select{internal|private}2 and cannot be referenced "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaves out fileprivate. Can you use Accessibility as the argument here, even if public and open don't make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

ERROR(versioned_attr_with_explicit_accessibility,
none, "'@_versioned' attribute can only be applied to internal "
"declarations, but %0 is %select{private|fileprivate|internal|public}1",
(Identifier, unsigned))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use Accessibility as the argument kind, and I suggest also capitalizing "INTERNAL" and "PUBLIC" (and "OPEN"?) to show that they should never occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done!

Neither of the following is supported:

func g<T>(_: T) {
  _ = {
    struct S {}
  }
}

struct G<T> {
  let fn = {
    struct S {}
  }
}

Even though nested generic types are supported, the second example
is more like a type inside a function than a type inside a type,
because 'S' has no parent type.

Technically this is source-breaking but since neither SILGen nor
IRGen knew how to generate code for these I doubt anything worked.
@slavapestov slavapestov force-pushed the resilience-diagnostics branch from a46e17a to 0438ce0 Compare January 10, 2017 00:49
…rguments model

Piggybacks some resilience diagnostics onto the availability
checking code.

Public and versioned functions with inlineable bodies can only
reference other public and internal entities, since the SIL code
for the function body is serialized and stored as part of the
module.

This includes @_transparent functions, @_inlineable functions,
accessors for @_inlineable storage, @inline(__always) functions,
and in Swift 4 mode, default argument expressions.

The new checks are a source-breaking change, however we don't
guarantee source compatibility for underscored attributes.

The new ABI and tests for the default argument model will come in
subsequent commits.
@slavapestov slavapestov force-pushed the resilience-diagnostics branch from 0438ce0 to d65d1d2 Compare January 10, 2017 00:59
@slavapestov
Copy link
Contributor Author

@jrose-apple I plan on re-visiting the whole ResilienceExpansion thing soon. I wanted to prototype the semantics and get some tests in first, though. I made the other fixes you suggested -- are you OK with this getting merged?

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - a46e17aaf370ab8a978d5a0221e472c82aa9be3a
Test requested by - @slavapestov

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 0ad118e into swiftlang:master Jan 10, 2017
@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - d65d1d2
Test requested by - @slavapestov

@jrose-apple
Copy link
Contributor

Yeah, I guess it's more important to start diagnosing things right now. I'll admit part of my discomfort is that ResilienceExpansion doesn't naturally make sense to me, even though it's such a simple enum. But that part shouldn't block you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants