From a3a29169ca415fb6a9a9f6c294572e8d235d78b5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 7 Apr 2017 11:52:53 +0800 Subject: Match - Replace DecisionTree with a sort+group algorithm --- Notes/MIR-Match.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Notes') diff --git a/Notes/MIR-Match.md b/Notes/MIR-Match.md index f47d2c88..cc95522c 100644 --- a/Notes/MIR-Match.md +++ b/Notes/MIR-Match.md @@ -20,3 +20,22 @@ For each index in the rule (all rules must be the same length) - Ranges sort after? + +Alternative Generator 2 +======================= + +Maintains match ordering + +1. Calculate branch rulesets (as existing) +1. While rules to process: + 1. Group based on shared values. + 1. Generate dispatch arm for each group + 1. Recurse into group, passing local _ as fallback (or parent _ if none) + +``` + +for + +``` + + -- cgit v1.2.3 From 8d0410a22f5aceca6cc438f444d442282ed4a656 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 23 Apr 2017 12:29:52 +0800 Subject: Notes - Add TODO to unify slot lvalues --- Notes/todo.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Notes') diff --git a/Notes/todo.txt b/Notes/todo.txt index 35526889..54956718 100644 --- a/Notes/todo.txt +++ b/Notes/todo.txt @@ -19,5 +19,7 @@ TODO: - Optimise typecheck. -- MIR: Add a Parameter type that is either LValue, Constant - > For any place a LValue is currently used, but a constant is valid +- MIR: Unify Variable/Argument/Temporary LValue types + - This should reduce the amount of code needed for validation, but will be a + BIG change. + -- cgit v1.2.3 From b42b112a3917536de023a8ff49ef045d79066363 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 12 May 2017 21:31:28 +0800 Subject: Notes - Add some random notes --- Notes/BigChanges/Variant.md | 70 +++++++++++++++++++++++++++++++++++++++++++++ Notes/BorrowChecker.md | 7 +++++ Notes/MIR-Validation.txt | 9 ++++++ 3 files changed, 86 insertions(+) create mode 100644 Notes/BigChanges/Variant.md create mode 100644 Notes/BorrowChecker.md create mode 100644 Notes/MIR-Validation.txt (limited to 'Notes') diff --git a/Notes/BigChanges/Variant.md b/Notes/BigChanges/Variant.md new file mode 100644 index 00000000..55bb3bb0 --- /dev/null +++ b/Notes/BigChanges/Variant.md @@ -0,0 +1,70 @@ + +(the below is from @ubsan) + +``` +// one can define their own variant, but I'm lazy +#include +#include +#include + +template +struct return_type {}; + +template +struct return_type()(std::declval())) +>> { + using type = decltype(std::declval()(std::declval())); +}; + +template +using return_type_t = typename return_type::type; + +// not sure what to call this +template +struct common_return_type { + using type = std::common_type_t...>; +}; + +template +using common_return_type_t = typename common_return_type::type; + +template +auto match( + std::variant& variant, F&& functor +) -> common_return_type_t { + // you could also use static_assert to make it SFINAE-unfriendly + return std::visit(functor, variant); +} + +template +struct overloaded : Fs... { + using Fs::operator()...; + overloaded(Fs&&... fs) : Fs(std::forward(fs))... { } +}; + +int main() { + auto var = std::variant(0); + std::cout << match(var, overloaded( + [](int i) { return i; }, + [](std::string s) { return 0; } + )); +} +``` + + + +ALTERNATIVE +=========== + +Could just update TU to have: +`` +stmt.if_let( +stmt.match_def( +stmt.match( + [](::MIR::LValue::Data_Assign& se) { + }, + [](::MIR::LValue::Data_Drop& se) { + } + ); +``` diff --git a/Notes/BorrowChecker.md b/Notes/BorrowChecker.md new file mode 100644 index 00000000..78b46ff5 --- /dev/null +++ b/Notes/BorrowChecker.md @@ -0,0 +1,7 @@ +- On borrow, calculate lifetime of asignment (using existing lifetime code) + - Ignore reborrows? +- Visit all statements in that lifetime and locate places where the borrow is propagated/stored + - Requires lifetime parameters on functions/&-ptrs to be present +- Assignment of the source value during the lifetime of the borrow is an error +- Dropping of the source value is an error +- Returning the borrow is an error diff --git a/Notes/MIR-Validation.txt b/Notes/MIR-Validation.txt new file mode 100644 index 00000000..337c65cd --- /dev/null +++ b/Notes/MIR-Validation.txt @@ -0,0 +1,9 @@ + +Requirements: +- Know full state (and linked states) for each path through the function. + + +Idea: +- Lifetime calculations (existing code) + - Mask out known invalid values at loopback. + -- cgit v1.2.3