From 2c31d6863c08775ebc452d6b91fc2a907bb440fc Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 22 Feb 2023 13:03:29 +0000 Subject: [PATCH 1/4] QL: Start on the AST for kind: predicates evaluator logs. --- ql/ql/src/codeql_ql/StructuredLogs.qll | 114 +++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/ql/ql/src/codeql_ql/StructuredLogs.qll b/ql/ql/src/codeql_ql/StructuredLogs.qll index 3de170fe350..9003837126d 100644 --- a/ql/ql/src/codeql_ql/StructuredLogs.qll +++ b/ql/ql/src/codeql_ql/StructuredLogs.qll @@ -126,6 +126,120 @@ module EvaluatorLog { } } +module KindPredicatesLog { + class SummaryHeader extends Object { + SummaryHeader() { exists(this.getString("summaryLogVersion")) } + + string getSummaryLogVersion() { result = this.getString("summaryLogVersion") } + + string getCodeqlVersion() { result = this.getString("codeqlVersion") } + + private string getStartTimeString() { result = this.getString("startTime") } + + predicate hasStartTime( + int year, string month, int day, int hours, int minute, int second, int millisecond + ) { + exists(string s, string r | + s = this.getStartTimeString() and + r = "(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})Z" + | + year = s.regexpCapture(r, 1).toInt() and + month = s.regexpCapture(r, 2) and + day = s.regexpCapture(r, 3).toInt() and + hours = s.regexpCapture(r, 4).toInt() and + minute = s.regexpCapture(r, 5).toInt() and + second = s.regexpCapture(r, 6).toInt() and + millisecond = s.regexpCapture(r, 7).toInt() + ) + } + } + + class AppearsAs extends Object { + SummaryEvent event; + + AppearsAs() { event.getObject("appearsAs") = this } + + SummaryEvent getSummaryEvent() { result = event } + + PredicateName getAPredicateName() { result.getAppearsAs() = this } + } + + class PredicateName extends Object { + AppearsAs appearsAs; + + PredicateName() { pragma[only_bind_out](appearsAs.getObject(_)) = this } + + AppearsAs getAppearsAs() { result = appearsAs } + + Query getAQuery() { result.getPredicateName() = this } + } + + class Query extends Array { + PredicateName predicateName; + + Query() { this = predicateName.getArray(_) } + + PredicateName getPredicateName() { result = predicateName } + } + + class SummaryEvent extends Object { + string evaluationStrategy; + + SummaryEvent() { evaluationStrategy = this.getString("evaluationStrategy") } + + string getEvaluationStrategy() { result = evaluationStrategy } + + string getRaHash() { result = this.getString("raHash") } + + string getPredicateName() { result = this.getString("predicateName") } + + string getCompletionTimeString() { result = this.getString("completionTime") } + + AppearsAs getAppearsAs() { result = this.getObject("appearsAs") } + + predicate hasCompletionTime( + int year, string month, int day, int hours, int minute, int second, int millisecond + ) { + exists(string s, string r | + s = this.getCompletionTimeString() and + r = "(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})Z" + | + year = s.regexpCapture(r, 1).toInt() and + month = s.regexpCapture(r, 2) and + day = s.regexpCapture(r, 3).toInt() and + hours = s.regexpCapture(r, 4).toInt() and + minute = s.regexpCapture(r, 5).toInt() and + second = s.regexpCapture(r, 6).toInt() and + millisecond = s.regexpCapture(r, 7).toInt() + ) + } + } + + class SentinelEmpty extends SummaryEvent { + SentinelEmpty() { evaluationStrategy = "SENTINEL_EMPTY" } + } + + class ComputeSimple extends SummaryEvent { + ComputeSimple() { evaluationStrategy = "COMPUTE_SIMPLE" } + } + + class ComputeRecursive extends SummaryEvent { + ComputeRecursive() { evaluationStrategy = "COMPUTE_RECURSIVE" } + } + + class InLayer extends SummaryEvent { + InLayer() { evaluationStrategy = "IN_LAYER" } + } + + class ComputedExtensional extends SummaryEvent { + ComputedExtensional() { evaluationStrategy = "COMPUTED_EXTENSIONAL" } + } + + class Extensional extends SummaryEvent { + Extensional() { evaluationStrategy = "EXTENSIONAL" } + } +} + // Stuff to test whether we've covered all event types private File logFile() { result = any(EvaluatorLog::LogHeader h).getLocation().getFile() } From 161acf0ebe9388fee04d77a21c90488d6b22d00a Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 22 Feb 2023 13:43:51 +0000 Subject: [PATCH 2/4] QL: Add more getters. --- ql/ql/src/codeql_ql/StructuredLogs.qll | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ql/ql/src/codeql_ql/StructuredLogs.qll b/ql/ql/src/codeql_ql/StructuredLogs.qll index 9003837126d..3c6e6f895b2 100644 --- a/ql/ql/src/codeql_ql/StructuredLogs.qll +++ b/ql/ql/src/codeql_ql/StructuredLogs.qll @@ -213,14 +213,43 @@ module KindPredicatesLog { millisecond = s.regexpCapture(r, 7).toInt() ) } + + int getResultSize() { result = this.getNumber("resultSize") } } class SentinelEmpty extends SummaryEvent { SentinelEmpty() { evaluationStrategy = "SENTINEL_EMPTY" } } + class PipeLineRun extends Object { + PipeLineRuns runs; + int index; + + PipeLineRun() { runs.getObject(index) = this } + + PipeLineRuns getArray() { result = runs } + + string getRaReference() { result = this.getString("raReference") } + + Array getCounts() { result = this.getArray("counts") } + + Array getDuplicationPercentages() { result = this.getArray("duplicationPercentages") } + } + + class PipeLineRuns extends Array { + SummaryEvent event; + + PipeLineRuns() { event.getArray("pipelineRuns") = this } + + SummaryEvent getEvent() { result = event } + + PipeLineRun getRun(int i) { result = this.getObject(i) } + } + class ComputeSimple extends SummaryEvent { ComputeSimple() { evaluationStrategy = "COMPUTE_SIMPLE" } + + PipeLineRun getPipelineRun() { result.getArray() = this.getArray("pipelineRuns") } } class ComputeRecursive extends SummaryEvent { From f155f19725bfe9930796f9da24b743afdf111f92 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 22 Feb 2023 14:15:18 +0000 Subject: [PATCH 3/4] QL: Respond to comments. --- ql/ql/src/codeql_ql/StructuredLogs.qll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ql/ql/src/codeql_ql/StructuredLogs.qll b/ql/ql/src/codeql_ql/StructuredLogs.qll index 3c6e6f895b2..f7e5c5b9184 100644 --- a/ql/ql/src/codeql_ql/StructuredLogs.qll +++ b/ql/ql/src/codeql_ql/StructuredLogs.qll @@ -189,7 +189,7 @@ module KindPredicatesLog { string getEvaluationStrategy() { result = evaluationStrategy } - string getRaHash() { result = this.getString("raHash") } + string getRAHash() { result = this.getString("raHash") } string getPredicateName() { result = this.getString("predicateName") } @@ -229,7 +229,7 @@ module KindPredicatesLog { PipeLineRuns getArray() { result = runs } - string getRaReference() { result = this.getString("raReference") } + string getRAReference() { result = this.getString("raReference") } Array getCounts() { result = this.getArray("counts") } From d64d03ec483eb779816bb998f97d98363262a368 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 22 Feb 2023 14:15:47 +0000 Subject: [PATCH 4/4] QL: Fix Code Scanning warning. --- ql/ql/src/codeql_ql/StructuredLogs.qll | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ql/ql/src/codeql_ql/StructuredLogs.qll b/ql/ql/src/codeql_ql/StructuredLogs.qll index f7e5c5b9184..3370e349c2f 100644 --- a/ql/ql/src/codeql_ql/StructuredLogs.qll +++ b/ql/ql/src/codeql_ql/StructuredLogs.qll @@ -223,9 +223,8 @@ module KindPredicatesLog { class PipeLineRun extends Object { PipeLineRuns runs; - int index; - PipeLineRun() { runs.getObject(index) = this } + PipeLineRun() { runs.getObject(_) = this } PipeLineRuns getArray() { result = runs }