From ea328f3f762c24b02df44f0a5d4c2e9cf64d0a61 Mon Sep 17 00:00:00 2001 From: Graham Nelson Date: Mon, 11 Apr 2022 16:08:37 +0100 Subject: [PATCH] Fix and test cases for Mantis bug 1921 --- inform7/Figures/timings-diagnostics.txt | 22 ++++---- .../PM_LateLeftTermWrongKind.txt | 4 ++ .../PM_LateRightTermWrongKind.txt | 4 ++ .../PM_LateLeftTermWrongKind.txt | 10 ++++ .../PM_LateRightTermWrongKind.txt | 10 ++++ .../Chapter 5/The Model World.w | 56 +++++++++++++++++++ 6 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 inform7/Tests/Test Problems/PM_LateLeftTermWrongKind.txt create mode 100644 inform7/Tests/Test Problems/PM_LateRightTermWrongKind.txt create mode 100644 inform7/Tests/Test Problems/_Results_Ideal/PM_LateLeftTermWrongKind.txt create mode 100644 inform7/Tests/Test Problems/_Results_Ideal/PM_LateRightTermWrongKind.txt diff --git a/inform7/Figures/timings-diagnostics.txt b/inform7/Figures/timings-diagnostics.txt index d0d3ba7c8..3584a7952 100644 --- a/inform7/Figures/timings-diagnostics.txt +++ b/inform7/Figures/timings-diagnostics.txt @@ -1,8 +1,8 @@ 100.0% in inform7 run - 68.2% in compilation to Inter - 47.8% in //Sequence::undertake_queued_tasks// + 68.0% in compilation to Inter + 47.7% in //Sequence::undertake_queued_tasks// 4.5% in //MajorNodes::pre_pass// - 3.1% in //MajorNodes::pass_1// + 3.2% in //MajorNodes::pass_1// 2.3% in //RTPhrasebook::compile_entries// 1.8% in //ImperativeDefinitions::assess_all// 1.5% in //RTKindConstructors::compile// @@ -18,20 +18,20 @@ 0.1% in //Task::make_built_in_kind_constructors// 0.1% in //Understand::traverse// 0.1% in //World::stages_II_and_III// - 2.2% not specifically accounted for - 29.0% in running Inter pipeline - 10.1% in step 14/15: generate inform6 -> auto.inf + 2.1% not specifically accounted for + 29.3% in running Inter pipeline + 10.2% in step 14/15: generate inform6 -> auto.inf 7.6% in step 5/15: load-binary-kits - 6.7% in step 6/15: make-synoptic-module - 1.6% in step 9/15: make-identifiers-unique + 6.8% in step 6/15: make-synoptic-module + 1.5% in step 9/15: make-identifiers-unique 0.4% in step 12/15: eliminate-redundant-operations 0.4% in step 4/15: compile-splats 0.4% in step 7/15: shorten-wiring - 0.3% in step 11/15: eliminate-redundant-labels 0.3% in step 8/15: detect-indirect-calls + 0.2% in step 11/15: eliminate-redundant-labels 0.1% in step 10/15: reconcile-verbs 0.1% in step 2/15: parse-insertions 0.1% in step 3/15: resolve-conditional-compilation - 0.5% not specifically accounted for - 2.3% in supervisor + 0.7% not specifically accounted for + 2.2% in supervisor 0.4% not specifically accounted for diff --git a/inform7/Tests/Test Problems/PM_LateLeftTermWrongKind.txt b/inform7/Tests/Test Problems/PM_LateLeftTermWrongKind.txt new file mode 100644 index 000000000..06fd4eb28 --- /dev/null +++ b/inform7/Tests/Test Problems/PM_LateLeftTermWrongKind.txt @@ -0,0 +1,4 @@ +Foo is a room. Boz is a room. +Quoggle relates various things to various things. +The verb to quog means the quoggle relation. +Boz quogs the player. diff --git a/inform7/Tests/Test Problems/PM_LateRightTermWrongKind.txt b/inform7/Tests/Test Problems/PM_LateRightTermWrongKind.txt new file mode 100644 index 000000000..d9d8ec581 --- /dev/null +++ b/inform7/Tests/Test Problems/PM_LateRightTermWrongKind.txt @@ -0,0 +1,4 @@ +Foo is a room. Boz is a room. +Quoggle relates various things to various things. +The verb to quog means the quoggle relation. +The player quogs Foo. diff --git a/inform7/Tests/Test Problems/_Results_Ideal/PM_LateLeftTermWrongKind.txt b/inform7/Tests/Test Problems/_Results_Ideal/PM_LateLeftTermWrongKind.txt new file mode 100644 index 000000000..18e8c88e1 --- /dev/null +++ b/inform7/Tests/Test Problems/_Results_Ideal/PM_LateLeftTermWrongKind.txt @@ -0,0 +1,10 @@ +Inform 7 v10.1.0 has started. +I've now read your source text, which is 27 words long. +I've also read Basic Inform by Graham Nelson, which is 7691 words long. +I've also read English Language by Graham Nelson, which is 2328 words long. +I've also read Standard Rules by Graham Nelson, which is 32092 words long. +Problem__ PM_LateLeftTermWrongKind + >--> You wrote 'Boz quogs the player' (source text, line 4), but I think the + kind of Boz is a room, and not a thing, which is what this relationship + would need it to be. (It relates a thing to a thing.) +Inform 7 has finished. diff --git a/inform7/Tests/Test Problems/_Results_Ideal/PM_LateRightTermWrongKind.txt b/inform7/Tests/Test Problems/_Results_Ideal/PM_LateRightTermWrongKind.txt new file mode 100644 index 000000000..7c65b32a2 --- /dev/null +++ b/inform7/Tests/Test Problems/_Results_Ideal/PM_LateRightTermWrongKind.txt @@ -0,0 +1,10 @@ +Inform 7 v10.1.0 has started. +I've now read your source text, which is 27 words long. +I've also read Basic Inform by Graham Nelson, which is 7691 words long. +I've also read English Language by Graham Nelson, which is 2328 words long. +I've also read Standard Rules by Graham Nelson, which is 32092 words long. +Problem__ PM_LateRightTermWrongKind + >--> You wrote 'The player quogs Foo' (source text, line 4), but I think the + kind of Foo is a room, and not a thing, which is what this relationship + would need it to be. (It relates a thing to a thing.) +Inform 7 has finished. diff --git a/inform7/knowledge-module/Chapter 5/The Model World.w b/inform7/knowledge-module/Chapter 5/The Model World.w index 4efe0f91a..40aa492fe 100644 --- a/inform7/knowledge-module/Chapter 5/The Model World.w +++ b/inform7/knowledge-module/Chapter 5/The Model World.w @@ -80,6 +80,7 @@ void World::stage_IV(void) { InferenceSubjects::check_model(infs); @; @; + @; } World::ask_plugins_at_stage(WORLD_STAGE_IV); } @@ -192,6 +193,61 @@ about the Portal, to stand. "which is impossible. When a kind's definition says that something is 'always' " "true, there is no way to override that for particular things of the kind."); +@ This is a last line of defence. Suppose we define "to connect to" as a relation +between things and things, and then write "X connects to Y". Inform must clearly +check that X and Y are both things. It does indeed make some checks along those +lines earlier on in compilation, but there are objects whose kinds are not known +until model completion time -- in particular, there can be objects which might +be things or might be rooms, so that we cannot know if "X connects to Y" is +legal until after the model is completed. + +But that's now! And so we make one last check, just in case. + +@ = + inference *inf; + POSITIVE_KNOWLEDGE_LOOP(inf, infs, relation_inf) { + binary_predicate *bp = RelationSubjects::to_bp(infs); + inference_subject *left_infs = NULL; + inference_subject *right_infs = NULL; + RelationInferences::get_term_subjects(inf, &left_infs, &right_infs); + instance *left_instance = InstanceSubjects::to_instance(left_infs); + instance *right_instance = InstanceSubjects::to_instance(right_infs); + kind *left_kind = Instances::to_kind(left_instance); + kind *right_kind = Instances::to_kind(right_instance); + kind *left_needed_kind = BinaryPredicates::term_kind(bp, 0); + kind *right_needed_kind = BinaryPredicates::term_kind(bp, 1); + if ((left_instance) && (Kinds::conforms_to(left_kind, left_needed_kind) == FALSE)) { + current_sentence = Inferences::where_inferred(inf); + Problems::quote_source(1, current_sentence); + Problems::quote_object(2, left_instance); + Problems::quote_kind(3, left_kind); + Problems::quote_kind(4, left_needed_kind); + Problems::quote_kind(5, right_needed_kind); + StandardProblems::handmade_problem(Task::syntax_tree(), + _p_(PM_LateLeftTermWrongKind)); + Problems::issue_problem_segment( + "You wrote %1, but I think the kind of %2 is %3, and not %4, " + "which is what this relationship would need it to be. (It " + "relates %4 to %5.)"); + Problems::issue_problem_end(); + } + if ((right_instance) && (Kinds::conforms_to(right_kind, right_needed_kind) == FALSE)) { + current_sentence = Inferences::where_inferred(inf); + Problems::quote_source(1, current_sentence); + Problems::quote_object(2, right_instance); + Problems::quote_kind(3, right_kind); + Problems::quote_kind(4, left_needed_kind); + Problems::quote_kind(5, right_needed_kind); + StandardProblems::handmade_problem(Task::syntax_tree(), + _p_(PM_LateRightTermWrongKind)); + Problems::issue_problem_segment( + "You wrote %1, but I think the kind of %2 is %3, and not %5, " + "which is what this relationship would need it to be. (It " + "relates %4 to %5.)"); + Problems::issue_problem_end(); + } + } + @h Stage V. A final chance to add properties which may assist the run-time implementation of whatever a plugin is concerned with, but which is not allowed to make