main-draft.hl.rkt (6178B)
1 #lang hyper-literate #:♦ #:no-auto-require (dotlambda/unhygienic . racket/base) 2 3 ♦require[scribble-math 4 racket/require 5 (for-label (subtract-in (only-meta-in 0 type-expander/lang) 6 subtemplate/override) 7 typed-worklist 8 type-expander/expander 9 phc-toolkit/untyped/aliases 10 phc-toolkit/untyped/syntax-parse 11 subtemplate/override)] 12 13 ♦title[#:style (with-html5 manual-doc-style) 14 #:tag "graph-draft" 15 #:tag-prefix "phc-graph/graph-draft"]{Draft of the implementation of 16 the graph macro} 17 18 ♦(chunks-toc-prefix 19 '("(lib phc-graph/scribblings/phc-graph-implementation.scrbl)" 20 "phc-graph/graph-draft")) 21 22 ♦chunk[<overview> 23 (define low-graph-impl 24 (syntax-parser 25 [<signature+metadata> 26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 27 |<phase 1: call mappings and extract placeholders>| 28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 29 |<phase 2: inline placeholders within node boundaries>| 30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 31 |<phase 3: replace indices with promises>| 32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 33 <equality-coalescing> 34 <invariants+auto-fill> 35 <inflexible-row-polymorphism> 36 <flexible-row-polymorphism> 37 <polymorphic-node-types-and-mappings> 38 ;<general-purpose-graph-algorithms> 39 ;<garbage-collection> 40 41 42 |<phase~1: call mappings and extract placeholders>| 43 ]))] 44 45 ♦chunk[<signature+metadata> 46 <signature> 47 <metadata>] 48 49 ♦chunk[<signature> 50 (_ graph-name 51 #:∀ (pvarₕ …) 52 ({~lit node} nodeᵢ [fieldᵢⱼ cᵢⱼ:colon field-τᵢⱼ] …) 53 … 54 ({~lit mapping} (mappingₖ [argₖₗ :colon arg-τₖₗ] …) 55 :colon result-τₖ 56 . bodyₖ) 57 …)] 58 59 ♦chunk[<metadata> 60 (void)] 61 62 ♦chunk[|<phase 1: call mappings and extract placeholders>| 63 '<worklist> 64 '<call-mapping-functions+placeholders> 65 '<extract-placeholders> ;; and put them into the worklist 66 ] 67 68 ♦chunk[|<phase~1: call mappings and extract placeholders>| 69 #'(begin 70 (define 71 #:∀ (pvarₕ …) 72 (graph-name [rootₖ : (Listof (List arg-τₖₗ …))] …) 73 74 ;; TODO: move these to a separate literate programming chunk 75 (define-type nodeᵢ (tagged nodeᵢ [fieldᵢⱼ cᵢⱼ field-τᵢⱼ] …)) 76 … 77 78 (define (make-placeholderₖ argₖₗ …) 79 (list 'placeholderₖ argₖₗ …)) 80 … 81 82 (worklist 83 (list rootₖ …) 84 ((λ ([args : (List arg-τₖₗ …)]) 85 (define-values (argₖₗ …) (apply values args)) 86 (define result 87 (let* ([mappingₖ make-placeholderₖ] 88 … 89 [argₖₗ 'convert-inflexible-to-flexible?] 90 … 91 [argₖₗ 'invariant-well-scopedness?] 92 …) 93 (error "NOT IMPL YET.787543") 94 ;. bodyₖ 95 '(bodyₖ))) 96 ;; returns placeholders + the result: 97 '(extract-placeholders result) 98 (error "NOT IMPL YET.8946513648")) 99 …) 100 ((List arg-τₖₗ …) result-τₖ) …)))] 101 102 ♦chunk[|<phase 1: call mappings and extract placeholders>| 103 ;; Phase 1: call the mapping functions on the input data 104 #'(: phase-1 (∀ (pvarₕ …) ;; or use this? (nodes-pvar … mapping-pvar … …) 105 (→ (List (Listof mapping-arg-type) ddd) 106 (List (Listof mapping-result-type) ddd)))) 107 #'(begin 108 ;; Maybe this should be done last, when all phases are available? 109 (define (phase1-many-roots (argₖₗ …) …) 'TODO) 110 (define (phase1-single-root-for-mapping (argₖₗ …)) 'TODO) 111 …)] 112 113 ♦chunk[|<phase 2: inline placeholders within node boundaries>| 114 ;; Phase 2: inline placeholders within node boundaries 115 '(generate-worklist 116 nodes 117 #'(…?)) 118 '{(funcion which for a mapping-result → inserts nodes into worklist) …} 119 '(for the root mapping results 120 call the function to insert nodes and keep the surrounding part) 121 '(for each mapping result 122 call the function to insert nodes)] 123 124 ♦chunk[|<phase 3: replace indices with promises>| 125 ;; Phase 3: Replace indices with promises 126 ;; Phase 3a: have an empty set of invariant witnesses, and call the 127 ;; invariants for checking 128 ;; Phase 3b: have the full set of invariant witnesses. 129 ;; TODO phase 3: auto-fill. 130 (void)] 131 132 ♦chunk[<equality-coalescing> 133 ;; implement as always-#f-unless-eq? for now 134 (void)] 135 ♦chunk[<invariants+auto-fill> 136 (void)] 137 ♦chunk[<inflexible-row-polymorphism> 138 (void)] 139 ♦chunk[<flexible-row-polymorphism> 140 (void)] 141 ♦chunk[<polymorphic-node-types-and-mappings> 142 (void)] 143 144 ♦chunk[<overview> 145 ; high-level graph API: 146 #;(<metadata2> 147 <extending-existing-graph-types> 148 <invariants-for-extended-graph-types> 149 <auto-generate-mappings>)] 150 151 Row polymorphism: make a generic struct->vector and vector->struct? 152 153 ♦chunk[<*> 154 (provide low-graph-impl 155 (for-template (all-from-out "literals.rkt"))) 156 157 (require (for-template (only-meta-in 0 type-expander/lang) 158 typed-worklist 159 phc-adt) 160 type-expander/expander 161 phc-toolkit/untyped/aliases 162 phc-toolkit/untyped/syntax-parse 163 subtemplate/override) 164 165 (require (for-template "literals.rkt")) 166 <overview>]