]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.tree.propagation: Propagate length slot of primitive resize calls
authortimor <timor.dd@googlemail.com>
Thu, 29 Jul 2021 21:19:47 +0000 (23:19 +0200)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 21 Dec 2021 15:19:25 +0000 (09:19 -0600)
basis/compiler/tree/propagation/known-words/known-words.factor
basis/compiler/tree/propagation/propagation-tests.factor

index 5c54c9f56e4ca08fc85f634a8f9f106af09a655b..dad34ccf3efbb44173eeee4761b9b86eff127d4e 100644 (file)
@@ -391,3 +391,16 @@ generic-comparison-ops [
 \ tag [
     drop fixnum 0 num-types get [a,b) <class/interval-info>
 ] "outputs" set-word-prop
+
+! Primitive resize operations
+
+: propagate-resize-fixed-length-sequence ( n-info in-info class -- out-info )
+    nip <sequence-info> ;
+
+{ { resize-array array }
+  { resize-byte-array byte-array }
+  { resize-string string } }
+[
+    [ propagate-resize-fixed-length-sequence ] curry
+    "outputs" set-word-prop
+] assoc-each
index 33321734c3d851a7c9114475e6368f30c6a15964..5a4b3dffc81d4ef5bc008f706291a706b194ceaa 100644 (file)
@@ -35,6 +35,15 @@ IN: compiler.tree.propagation.tests
     [ dup "foo" <array> drop ] final-info first
 ] unit-test
 
+{ t } [
+    [ resize-array length ] final-info first
+    array-capacity <class-info> =
+] unit-test
+
+{ 42 } [
+    [ 42 swap resize-array length ] final-literals first
+] unit-test
+
 ! Byte arrays
 { V{ 3 } } [
     [ 3 <byte-array> length ] final-literals
@@ -46,8 +55,12 @@ IN: compiler.tree.propagation.tests
 ] unit-test
 
 { t } [
-    [ dupd resize-byte-array drop ] final-info first
-    integer-array-capacity <class-info> =
+    [ resize-byte-array length ] final-info first
+    array-capacity <class-info> =
+] unit-test
+
+{ 43 } [
+    [ 43 swap resize-byte-array length ] final-literals first
 ] unit-test
 
 ! Strings
@@ -55,6 +68,15 @@ IN: compiler.tree.propagation.tests
     [ 3 f <string> length ] final-literals
 ] unit-test
 
+{ t } [
+    [ resize-string length ] final-info first
+    array-capacity <class-info> =
+] unit-test
+
+{ V{ 44 } } [
+    [ 44 swap resize-string length ] final-literals
+] unit-test
+
 { V{ t } } [
     [ { string } declare string? ] final-classes
 ] unit-test