Skip to content

Commit 97612ad

Browse files
committed
LifetimeDependence type checker diagnostic IDs and messages
Rework the type checker's diagnostics to support completely checking lifetime dependence requirements. Don't let anything through without the feature being enabled and complete annotation or inference.
1 parent 6adc65b commit 97612ad

File tree

1 file changed

+69
-31
lines changed

1 file changed

+69
-31
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8089,7 +8089,7 @@ ERROR(pack_iteration_where_clause_not_supported, none,
80898089

80908090

80918091
//------------------------------------------------------------------------------
8092-
// MARK: Lifetime Dependence Diagnostics
8092+
// MARK: Lifetime Dependence Syntax
80938093
//------------------------------------------------------------------------------
80948094

80958095
ERROR(lifetime_dependence_invalid_param_name, none,
@@ -8108,34 +8108,15 @@ ERROR(lifetime_dependence_cannot_use_kind, none,
81088108
ERROR(lifetime_dependence_cannot_use_parsed_scoped_consuming, none,
81098109
"invalid use of scoped lifetime dependence with consuming ownership",
81108110
())
8111-
ERROR(lifetime_dependence_cannot_use_inferred_scoped_consuming, none,
8112-
"invalid use of lifetime dependence on an Escapable parameter with "
8113-
"consuming ownership",
8114-
())
8115-
ERROR(lifetime_dependence_invalid_self_ownership, none,
8116-
"invalid scoped lifetime dependence on an Escapable self with consuming "
8117-
"ownership",
8118-
())
81198111
ERROR(lifetime_dependence_only_on_function_method_init_result, none,
81208112
"lifetime dependence specifiers may only be used on result of "
81218113
"functions, methods, initializers", ())
8122-
ERROR(lifetime_dependence_invalid_type, none,
8123-
"lifetime dependence can only be specified on ~Escapable types", ())
8124-
ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
8125-
"cannot infer lifetime dependence %0, multiple parameters qualifiy as a candidate", (StringRef))
8126-
ERROR(lifetime_dependence_cannot_infer_no_candidates, none,
8127-
"cannot infer lifetime dependence%0, no parameters found that are either "
8128-
"~Escapable or Escapable with a borrowing ownership", (StringRef))
8129-
ERROR(lifetime_dependence_ctor_non_self_or_nil_return, none,
8130-
"expected nil or self as return values in an initializer with "
8131-
"lifetime dependent specifiers",
8132-
())
8133-
ERROR(lifetime_dependence_cannot_be_applied_to_tuple_elt, none,
8134-
"lifetime dependence specifiers cannot be applied to tuple elements", ())
8135-
ERROR(lifetime_dependence_method_escapable_bitwisecopyable_self, none,
8136-
"cannot infer lifetime dependence on a self which is BitwiseCopyable & "
8137-
"Escapable",
8114+
ERROR(lifetime_dependence_ctor_non_self_or_nil_return, none,
8115+
"expected 'nil' or 'self' as return values in an initializer with "
8116+
"lifetime dependent specifiers",
81388117
())
8118+
ERROR(lifetime_dependence_cannot_be_applied_to_tuple_elt, none,
8119+
"lifetime dependence specifiers cannot be applied to tuple elements", ())
81398120
ERROR(lifetime_dependence_immortal_conflict_name, none,
81408121
"conflict between the parameter name and 'immortal' contextual keyword", ())
81418122
ERROR(lifetime_dependence_function_type, none,
@@ -8144,18 +8125,75 @@ ERROR(lifetime_dependence_function_type, none,
81448125
ERROR(lifetime_dependence_immortal_alone, none,
81458126
"cannot specify any other dependence source along with immortal", ())
81468127
ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
8147-
"invalid lifetime dependence on a source of Escapable type, use borrow "
8148-
"dependence instead",
8149-
())
8128+
"cannot copy the lifetime of an Escapable type, use "
8129+
"'@lifetime(borrow %0)' instead",
8130+
(StringRef))
81508131
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
81518132
"invalid use of borrow dependence with consuming ownership",
81528133
())
8134+
ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
8135+
"invalid use of borrow dependence on the same inout parameter",
8136+
())
81538137
ERROR(lifetime_dependence_duplicate_target, none,
81548138
"invalid duplicate target lifetime dependencies on function", ())
8139+
ERROR(lifetime_parameter_requires_inout, none,
8140+
"lifetime-dependent parameter must be 'inout'", (Identifier))
8141+
8142+
//------------------------------------------------------------------------------
8143+
// MARK: Lifetime Dependence Requirements
8144+
//------------------------------------------------------------------------------
8145+
8146+
ERROR(lifetime_dependence_feature_required_return, none,
8147+
"%0 with a ~Escapable result requires "
8148+
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8149+
ERROR(lifetime_dependence_feature_required_mutating, none,
8150+
"%0 with ~Escapable 'self' requires "
8151+
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8152+
ERROR(lifetime_dependence_feature_required_inout, none,
8153+
"%0 with a ~Escapable 'inout' parameter requires "
8154+
"'-enable-experimental-feature LifetimeDependence'",
8155+
// arg list is interchangable with lifetime_dependence_cannot_infer_inout
8156+
(StringRef, Identifier))
8157+
8158+
ERROR(lifetime_dependence_cannot_infer_return, none,
8159+
"%0 with a ~Escapable result requires '@lifetime(...)'", (StringRef))
8160+
ERROR(lifetime_dependence_cannot_infer_mutating, none,
8161+
"%0 with a ~Escapable 'self' requires '@lifetime(self: ...)'", (StringRef))
8162+
ERROR(lifetime_dependence_cannot_infer_inout, none,
8163+
"%0 with a ~Escapable 'inout' parameter requires '@lifetime(%1: ...)'",
8164+
(StringRef, Identifier))
8165+
8166+
//------------------------------------------------------------------------------
8167+
// MARK: Lifetime Dependence Inference - refinements to the requirements above
8168+
//------------------------------------------------------------------------------
81558169

8156-
ERROR(lifetime_dependence_feature_required, none,
8157-
"returning ~Escapable type requires '-enable-experimental-feature "
8158-
"LifetimeDependence'", ())
8170+
ERROR(lifetime_dependence_cannot_infer_return_no_param, none,
8171+
"%0 with a ~Escapable result needs a parameter to depend on",
8172+
(StringRef))
8173+
NOTE(lifetime_dependence_cannot_infer_return_immortal, none,
8174+
"'@lifetime(immortal)' can be used to indicate that values produced by "
8175+
"this initializer have no lifetime dependencies", ())
8176+
ERROR(lifetime_dependence_cannot_infer_bitwisecopyable, none,
8177+
"cannot infer lifetime dependence on %0 because '%1' is BitwiseCopyable, "
8178+
"specify '@lifetime(borrow self)'",
8179+
(StringRef, StringRef))
8180+
ERROR(lifetime_dependence_cannot_infer_kind, none,
8181+
"cannot infer the lifetime dependence scope on %0 with a ~Escapable "
8182+
"parameter, specify '@lifetime(borrow %1)' or '@lifetime(copy %1)'",
8183+
(StringRef, StringRef))
8184+
ERROR(lifetime_dependence_cannot_infer_scope_ownership, none,
8185+
"cannot borrow the lifetime of '%0', which has consuming ownership on %1",
8186+
(StringRef, StringRef))
8187+
8188+
//------------------------------------------------------------------------------
8189+
// MARK: Lifetime Dependence Experimental Inference
8190+
//------------------------------------------------------------------------------
8191+
8192+
ERROR(lifetime_dependence_cannot_infer_no_candidates, none,
8193+
"cannot infer lifetime dependence%0, no parameters found that are either "
8194+
"~Escapable or Escapable with a borrowing ownership", (StringRef))
8195+
ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
8196+
"cannot infer lifetime dependence%0, multiple parameters qualify as a candidate", (StringRef))
81598197

81608198
//===----------------------------------------------------------------------===//
81618199
// MARK: Sending

0 commit comments

Comments
 (0)