@@ -76,6 +76,11 @@ ExpressionTimer::~ExpressionTimer() {
76
76
if (!PrintWarning)
77
77
return ;
78
78
79
+ const auto WarnLimit = getWarnLimit ();
80
+
81
+ if (WarnLimit == 0 || elapsedMS < WarnLimit)
82
+ return ;
83
+
79
84
ASTNode anchor;
80
85
if (auto *locator = Anchor.dyn_cast <ConstraintLocator *>()) {
81
86
anchor = simplifyLocatorToAnchor (locator);
@@ -87,9 +92,7 @@ ExpressionTimer::~ExpressionTimer() {
87
92
anchor = Anchor.get <Expr *>();
88
93
}
89
94
90
- const auto WarnLimit = getWarnLimit ();
91
- if (WarnLimit != 0 && elapsedMS >= WarnLimit &&
92
- anchor.getStartLoc ().isValid ()) {
95
+ if (anchor.getStartLoc ().isValid ()) {
93
96
Context.Diags
94
97
.diagnose (anchor.getStartLoc (), diag::debug_long_expression, elapsedMS,
95
98
WarnLimit)
@@ -4758,6 +4761,12 @@ void constraints::simplifyLocator(ASTNode &anchor,
4758
4761
path = path.slice (1 );
4759
4762
continue ;
4760
4763
}
4764
+
4765
+ if (anchor.is <Pattern *>()) {
4766
+ path = path.slice (1 );
4767
+ continue ;
4768
+ }
4769
+
4761
4770
break ;
4762
4771
4763
4772
case ConstraintLocator::SubscriptMember:
@@ -4811,16 +4820,28 @@ void constraints::simplifyLocator(ASTNode &anchor,
4811
4820
}
4812
4821
4813
4822
case ConstraintLocator::Condition: {
4814
- anchor = castToExpr<IfExpr>(anchor)->getCondExpr ();
4823
+ if (auto *condStmt = getAsStmt<LabeledConditionalStmt>(anchor)) {
4824
+ anchor = &condStmt->getCond ().front ();
4825
+ } else {
4826
+ anchor = castToExpr<IfExpr>(anchor)->getCondExpr ();
4827
+ }
4828
+
4815
4829
path = path.slice (1 );
4816
4830
continue ;
4817
4831
}
4818
4832
4819
4833
case ConstraintLocator::TernaryBranch: {
4820
4834
auto branch = path[0 ].castTo <LocatorPathElt::TernaryBranch>();
4821
- auto *ifExpr = castToExpr<IfExpr>(anchor);
4822
4835
4823
- anchor = branch.forThen () ? ifExpr->getThenExpr () : ifExpr->getElseExpr ();
4836
+ if (auto *ifStmt = getAsStmt<IfStmt>(anchor)) {
4837
+ anchor =
4838
+ branch.forThen () ? ifStmt->getThenStmt () : ifStmt->getElseStmt ();
4839
+ } else {
4840
+ auto *ifExpr = castToExpr<IfExpr>(anchor);
4841
+ anchor =
4842
+ branch.forThen () ? ifExpr->getThenExpr () : ifExpr->getElseExpr ();
4843
+ }
4844
+
4824
4845
path = path.slice (1 );
4825
4846
continue ;
4826
4847
}
@@ -4851,8 +4872,77 @@ void constraints::simplifyLocator(ASTNode &anchor,
4851
4872
continue ;
4852
4873
}
4853
4874
4854
- default :
4855
- // FIXME: Lots of other cases to handle.
4875
+ case ConstraintLocator::ClosureBodyElement: {
4876
+ auto bodyElt = path[0 ].castTo <LocatorPathElt::ClosureBodyElement>();
4877
+ anchor = bodyElt.getElement ();
4878
+ path = path.slice (1 );
4879
+ continue ;
4880
+ }
4881
+
4882
+ case ConstraintLocator::PatternMatch: {
4883
+ auto patternElt = path[0 ].castTo <LocatorPathElt::PatternMatch>();
4884
+ anchor = patternElt.getPattern ();
4885
+ path = path.slice (1 );
4886
+ continue ;
4887
+ }
4888
+
4889
+ case ConstraintLocator::PackType:
4890
+ case ConstraintLocator::ParentType:
4891
+ case ConstraintLocator::KeyPathType:
4892
+ case ConstraintLocator::InstanceType:
4893
+ case ConstraintLocator::PlaceholderType:
4894
+ case ConstraintLocator::SequenceElementType:
4895
+ case ConstraintLocator::ConstructorMemberType:
4896
+ case ConstraintLocator::ExistentialSuperclassType:
4897
+ break ;
4898
+
4899
+ case ConstraintLocator::GenericArgument:
4900
+ case ConstraintLocator::FunctionArgument:
4901
+ case ConstraintLocator::SynthesizedArgument:
4902
+ break ;
4903
+
4904
+ case ConstraintLocator::DynamicLookupResult:
4905
+ case ConstraintLocator::KeyPathComponentResult:
4906
+ break ;
4907
+
4908
+ case ConstraintLocator::GenericParameter:
4909
+ break ;
4910
+
4911
+ case ConstraintLocator::OpenedGeneric:
4912
+ case ConstraintLocator::OpenedOpaqueArchetype:
4913
+ break ;
4914
+
4915
+ case ConstraintLocator::KeyPathRoot:
4916
+ case ConstraintLocator::KeyPathValue:
4917
+ break ;
4918
+
4919
+ case ConstraintLocator::ProtocolRequirement:
4920
+ case ConstraintLocator::ConditionalRequirement:
4921
+ case ConstraintLocator::ConformanceRequirement:
4922
+ case ConstraintLocator::TypeParameterRequirement:
4923
+ break ;
4924
+
4925
+ case ConstraintLocator::PackElement:
4926
+ break ;
4927
+
4928
+ case ConstraintLocator::PatternBindingElement: {
4929
+ auto pattern = path[0 ].castTo <LocatorPathElt::PatternBindingElement>();
4930
+ auto *patternBinding = cast<PatternBindingDecl>(anchor.get <Decl *>());
4931
+ anchor = patternBinding->getInit (pattern.getIndex ());
4932
+ // If this pattern is uninitialized, let's use it as anchor.
4933
+ if (!anchor)
4934
+ anchor = patternBinding->getPattern (pattern.getIndex ());
4935
+ path = path.slice (1 );
4936
+ continue ;
4937
+ }
4938
+
4939
+ case ConstraintLocator::ImplicitConversion:
4940
+ break ;
4941
+
4942
+ case ConstraintLocator::Witness:
4943
+ case ConstraintLocator::WrappedValue:
4944
+ case ConstraintLocator::OptionalPayload:
4945
+ case ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice:
4856
4946
break ;
4857
4947
}
4858
4948
0 commit comments