Skip to content

Commit 724d11e

Browse files
committed
Added fatal type error handling to purecalc & peephole
init commit_hash:b89977a75ce7119bfd34312b41e9382a28f13adc
1 parent 13374e0 commit 724d11e

File tree

14 files changed

+158
-61
lines changed

14 files changed

+158
-61
lines changed

yql/essentials/core/facade/yql_facade.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,49 +1725,6 @@ TIssues TProgram::CompletedIssues() const {
17251725
return result;
17261726
}
17271727

1728-
void TProgram::CheckFatalIssues(TIssues& issues) const {
1729-
bool isFatal = false;
1730-
auto checkIssue = [&](const TIssue& issue) {
1731-
if (issue.GetSeverity() == TSeverityIds::S_FATAL) {
1732-
isFatal = true;
1733-
}
1734-
};
1735-
1736-
std::function<void(const TIssuePtr& issue)> recursiveCheck = [&](const TIssuePtr& issue) {
1737-
if (isFatal) {
1738-
return;
1739-
}
1740-
1741-
checkIssue(*issue);
1742-
for (const auto& subissue : issue->GetSubIssues()) {
1743-
recursiveCheck(subissue);
1744-
}
1745-
};
1746-
1747-
for (const auto& issue : issues) {
1748-
if (isFatal) {
1749-
break;
1750-
}
1751-
1752-
checkIssue(issue);
1753-
// check subissues
1754-
for (const auto& subissue : issue.GetSubIssues()) {
1755-
recursiveCheck(subissue);
1756-
}
1757-
}
1758-
1759-
if (isFatal) {
1760-
TIssue result;
1761-
result.SetMessage(
1762-
TStringBuilder()
1763-
<< "An abnormal situation found, so consider opening a bug report to YQL (st/YQLSUPPORT),"
1764-
<< " because more detailed information is only available in server side logs and/or "
1765-
<< "coredumps.");
1766-
result.SetCode(TIssuesIds::UNEXPECTED, TSeverityIds::S_FATAL);
1767-
issues.AddIssue(result);
1768-
}
1769-
}
1770-
17711728
TIssue MakeNoBlocksInfoIssue(const TVector<TString>& names, bool isTypes) {
17721729
TIssue result;
17731730
TString msg = TStringBuilder() << "Most frequent " << (isTypes ? "types " : "callables ")

yql/essentials/core/facade/yql_facade.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ class TProgram: public TThrRefBase, private TNonCopyable
375375

376376
private:
377377
std::optional<bool> CheckFallbackIssues(const TIssues& issues);
378-
void CheckFatalIssues(TIssues& issues) const;
379378
void HandleSourceCode(TString& sourceCode);
380379
void HandleTranslationSettings(NSQLTranslation::TTranslationSettings& loadedSettings,
381380
const NSQLTranslation::TTranslationSettings*& currentSettings);

yql/essentials/core/issue/yql_issue.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "yql_issue.h"
22

3+
#include <util/string/builder.h>
4+
35
namespace NYql {
46

57
const char IssueMapResource[] = "yql_issue.txt";
@@ -8,4 +10,48 @@ static_assert(DEFAULT_ERROR == TIssuesIds::DEFAULT_ERROR,
810
"value of particular and common error mismatched for \"DEFAULT_ERROR\"");
911
static_assert(UNEXPECTED_ERROR == TIssuesIds::UNEXPECTED,
1012
"value of particular and common error mismatched for \"UNEXPECTED_ERROR\"");
13+
14+
void CheckFatalIssues(TIssues& issues) {
15+
bool isFatal = false;
16+
auto checkIssue = [&](const TIssue& issue) {
17+
if (issue.GetSeverity() == TSeverityIds::S_FATAL) {
18+
isFatal = true;
19+
}
20+
};
21+
22+
std::function<void(const TIssuePtr& issue)> recursiveCheck = [&](const TIssuePtr& issue) {
23+
if (isFatal) {
24+
return;
25+
}
26+
27+
checkIssue(*issue);
28+
for (const auto& subissue : issue->GetSubIssues()) {
29+
recursiveCheck(subissue);
30+
}
31+
};
32+
33+
for (const auto& issue : issues) {
34+
if (isFatal) {
35+
break;
36+
}
37+
38+
checkIssue(issue);
39+
// check subissues
40+
for (const auto& subissue : issue.GetSubIssues()) {
41+
recursiveCheck(subissue);
42+
}
43+
}
44+
45+
if (isFatal) {
46+
TIssue result;
47+
result.SetMessage(
48+
TStringBuilder()
49+
<< "An abnormal situation found, so consider opening a bug report to YQL (st/YQLSUPPORT),"
50+
<< " because more detailed information is only available in server side logs and/or "
51+
<< "coredumps.");
52+
result.SetCode(TIssuesIds::UNEXPECTED, TSeverityIds::S_FATAL);
53+
issues.AddIssue(result);
54+
}
55+
}
56+
1157
}

yql/essentials/core/issue/yql_issue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ inline TIssue YqlIssue(const TPosition& position, EYqlIssueCode id) {
4848
return YqlIssue(position, id, IssueCodeToString(id));
4949
}
5050

51+
void CheckFatalIssues(TIssues& issues);
52+
5153
}

yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,14 +2305,52 @@ IGraphTransformer::TStatus PeepHoleBlockStage(const TExprNode::TPtr& input, TExp
23052305
}, ctx, settings);
23062306
}
23072307

2308+
class TStrongTypeErrorProxy : public IGraphTransformer {
2309+
public:
2310+
TStrongTypeErrorProxy(IGraphTransformer& inner)
2311+
: Inner_(inner)
2312+
{}
2313+
2314+
TStatus Transform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final {
2315+
auto status = Inner_.Transform(input, output, ctx);
2316+
CheckFatalTypeError(status);
2317+
return status;
2318+
}
2319+
2320+
NThreading::TFuture<void> GetAsyncFuture(const TExprNode& input) final {
2321+
return Inner_.GetAsyncFuture(input);
2322+
}
2323+
2324+
TStatus ApplyAsyncChanges(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final {
2325+
auto status = Inner_.ApplyAsyncChanges(input, output, ctx);
2326+
CheckFatalTypeError(status);
2327+
return status;
2328+
}
2329+
2330+
void Rewind() final {
2331+
return Inner_.Rewind();
2332+
}
2333+
2334+
TStatistics GetStatistics() const final {
2335+
return Inner_.GetStatistics();
2336+
}
2337+
2338+
private:
2339+
IGraphTransformer& Inner_;
2340+
};
2341+
2342+
TAutoPtr<IGraphTransformer> MakeStrongTypeErrorProxy(IGraphTransformer& inner) {
2343+
return new TStrongTypeErrorProxy(inner);
2344+
}
2345+
23082346
template<bool FinalStage>
23092347
void AddStandardTransformers(TTransformationPipeline& pipelene, IGraphTransformer* typeAnnotator) {
23102348
auto issueCode = TIssuesIds::CORE_EXEC;
23112349
pipelene.AddServiceTransformers(issueCode);
23122350
if (typeAnnotator) {
2313-
pipelene.Add(*typeAnnotator, "TypeAnnotation", issueCode);
2351+
pipelene.Add(MakeStrongTypeErrorProxy(*typeAnnotator), "TypeAnnotation", issueCode);
23142352
} else {
2315-
pipelene.AddTypeAnnotationTransformer(issueCode);
2353+
pipelene.AddTypeAnnotationTransformerWithMode(issueCode, ETypeCheckMode::Repeat);
23162354
}
23172355

23182356
pipelene.AddPostTypeAnnotation(true, FinalStage, issueCode);

yql/essentials/core/services/yql_transform_pipeline.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ TTransformationPipeline& TTransformationPipeline::AddTypeAnnotationTransformer(
259259
return *this;
260260
}
261261

262+
TTransformationPipeline& TTransformationPipeline::AddTypeAnnotationTransformerWithMode(EYqlIssueCode issueCode, ETypeCheckMode mode) {
263+
auto callableTransformer = CreateExtCallableTypeAnnotationTransformer(*TypeAnnotationContext_);
264+
AddTypeAnnotationTransformer(callableTransformer, issueCode, mode);
265+
return *this;
266+
}
267+
262268
TTransformationPipeline& TTransformationPipeline::AddTypeAnnotationTransformer(EYqlIssueCode issueCode, bool twoStages)
263269
{
264270
if (twoStages) {

yql/essentials/core/services/yql_transform_pipeline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class TTransformationPipeline
4343
TTransformationPipeline& AddTableMetadataLoaderTransformer(EYqlIssueCode issueCode = TIssuesIds::CORE_TABLE_METADATA_LOADER);
4444
TTransformationPipeline& AddTypeAnnotationTransformer(TAutoPtr<IGraphTransformer> callableTransformer, EYqlIssueCode issueCode = TIssuesIds::CORE_TYPE_ANN,
4545
ETypeCheckMode mode = ETypeCheckMode::Single);
46+
TTransformationPipeline& AddTypeAnnotationTransformerWithMode(EYqlIssueCode issueCode = TIssuesIds::CORE_TYPE_ANN,
47+
ETypeCheckMode mode = ETypeCheckMode::Single);
4648
TTransformationPipeline& AddTypeAnnotationTransformer(EYqlIssueCode issueCode = TIssuesIds::CORE_TYPE_ANN, bool twoStages = false);
4749

4850
TTransformationPipeline& Add(TAutoPtr<IGraphTransformer> transformer, const TString& stageName,

yql/essentials/core/type_ann/type_ann_expr.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class TTypeAnnotationTransformer : public TGraphTransformerBase {
7070
IsComplete = true;
7171
}
7272

73-
if (Mode == ETypeCheckMode::Repeat && status == TStatus::Error) {
74-
throw yexception() << "Detected a type error after initial validation";
73+
if (Mode == ETypeCheckMode::Repeat) {
74+
CheckFatalTypeError(status);
7575
}
7676

7777
return status;
@@ -110,6 +110,10 @@ class TTypeAnnotationTransformer : public TGraphTransformerBase {
110110
Processed.clear();
111111
}
112112

113+
if (Mode == ETypeCheckMode::Repeat) {
114+
CheckFatalTypeError(combinedStatus);
115+
}
116+
113117
return combinedStatus;
114118
}
115119

@@ -712,4 +716,10 @@ TExprNode::TPtr ParseAndAnnotate(
712716
return exprRoot;
713717
}
714718

719+
void CheckFatalTypeError(IGraphTransformer::TStatus status) {
720+
if (status == IGraphTransformer::TStatus::Error) {
721+
throw yexception() << "Detected a type error after initial validation";
722+
}
723+
}
724+
715725
} // namespace NYql

yql/essentials/core/type_ann/type_ann_expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ TExprNode::TPtr ParseAndAnnotate(
3333
TExprContext& exprCtx, bool instant, bool wholeProgram,
3434
TTypeAnnotationContext& typeAnnotationContext);
3535

36+
void CheckFatalTypeError(IGraphTransformer::TStatus status);
37+
3638
}

yql/essentials/public/purecalc/common/program_factory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ TProgramFactory::TProgramFactory(const TProgramFactoryOptions& options)
2727
UserData_ = GetYqlModuleResolver(ExprContext_, ModuleResolver_, Options_.UserData_, {}, {});
2828

2929
if (!ModuleResolver_) {
30-
ythrow TCompileError("", ExprContext_.IssueManager.GetIssues().ToString()) << "failed to compile modules";
30+
auto issues = ExprContext_.IssueManager.GetIssues();
31+
CheckFatalIssues(issues);
32+
ythrow TCompileError("", issues.ToString()) << "failed to compile modules";
3133
}
3234

3335
TVector<TString> UDFsPaths;

0 commit comments

Comments
 (0)