Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 666 - (view) (download)

1 : blume 275 (*
2 : blume 282 * Bundling information pertaining to one SML source file.
3 :     * - only includes information that does not require running
4 :     * the machine-dependent part of the compiler
5 : blume 275 *
6 :     * (C) 1999 Lucent Technologies, Bell Laboratories
7 :     *
8 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
9 :     *)
10 : blume 270 signature SMLINFO = sig
11 :    
12 :     type info
13 : blume 305 type ord_key = info
14 : blume 270
15 : blume 295 type complainer = GenericVC.ErrorMsg.complainer
16 : blume 297 type ast = GenericVC.Ast.dec
17 :     type region = GenericVC.SourceMap.region
18 : blume 299 type source = GenericVC.Source.inputSource
19 : blume 274
20 : blume 537 type attribs =
21 : blume 592 { split: bool,
22 :     is_rts: bool,
23 :     explicit_core_sym: Symbol.symbol option,
24 : blume 537 extra_compenv: GenericVC.Environment.staticEnv option }
25 :    
26 : blume 279 val eq : info * info -> bool (* compares sourcepaths *)
27 :     val compare : info * info -> order (* compares sourcepaths *)
28 :    
29 : blume 487 (* The idea behind "newGeneration" is the following:
30 :     * Before parsing .cm files (on behalf of CM.make/recomp or CMB.make etc.)
31 :     * we start a new generation. While parsing, when we encounter a new
32 :     * SML source we re-use existing information and bump its generation
33 :     * number to "now". After we are done with one group we can safely
34 :     * evict all info records for files in this group if their generation
35 :     * is not "now".
36 :     * Moreover, if we encounter an entry that has a different owner group,
37 :     * we can either signal an error (if the generation is "now" which means
38 :     * that the file was found in another group during the same parse) or
39 :     * issue a "switched groups" warning (if the generation is older than
40 :     * now which means that the file used to be in another group). *)
41 :     val newGeneration : unit -> unit
42 :    
43 : blume 299 val info : GeneralParams.info ->
44 : blume 666 { sourcepath: SrcPath.file,
45 :     group: SrcPath.file * region,
46 : blume 537 sh_spec: Sharing.request }
47 : blume 270 -> info
48 :    
49 : blume 537 val info' : attribs -> GeneralParams.info ->
50 : blume 666 { sourcepath: SrcPath.file,
51 :     group: SrcPath.file * region,
52 : blume 537 sh_spec: Sharing.request }
53 :     -> info
54 :    
55 : blume 666 val sourcepath : info -> SrcPath.file
56 : blume 354 val skelname : info -> string
57 :     val binname : info -> string
58 : blume 666 val group : info -> SrcPath.file
59 : blume 299 val error : GeneralParams.info -> info -> complainer
60 : blume 277
61 : blume 299 val parsetree : GeneralParams.info -> info -> (ast * source) option
62 : blume 301 val exports : GeneralParams.info -> info -> SymbolSet.set option
63 :     val skeleton : GeneralParams.info -> info -> Skeleton.decl option
64 : blume 387 val sh_spec : info -> Sharing.request
65 :     val set_sh_mode : info * Sharing.mode -> unit
66 :     val sh_mode : info -> Sharing.mode
67 : blume 537 val attribs : info -> attribs
68 : blume 301 val lastseen : info -> TStamp.t
69 : blume 279
70 : blume 301 (* forget a parse tree that we are done with *)
71 :     val forgetParsetree : info -> unit
72 :    
73 : blume 487 (* Evict all elements that belong to a given group but which
74 :     * are not of the current generation. "cleanGroup" should be
75 : blume 514 * called right after finishing to parse the group file.
76 :     * If the boolean flag ("nowStable") is set to true, then all
77 :     * members of the group are dismissed regardless of their
78 :     * generation. This is used to get rid of the information for
79 :     * members of now-stable libraries. *)
80 : blume 666 val cleanGroup : bool -> SrcPath.file -> unit
81 : blume 301
82 : blume 537 (* See if a given piece of info is (still) known here: *)
83 :     val isKnown : info -> bool
84 :    
85 : blume 487 (* Delete all known info. *)
86 :     val reset : unit -> unit
87 :    
88 : blume 280 (* different ways of describing an sml file using group and source *)
89 : blume 354 val descr : info -> string (* sname *)
90 : blume 305
91 : blume 306 val errorLocation : GeneralParams.info -> info -> string
92 : blume 270 end
93 :    
94 :     structure SmlInfo :> SMLINFO = struct
95 :    
96 : blume 275 structure Source = GenericVC.Source
97 :     structure SF = GenericVC.SmlFile
98 :     structure EM = GenericVC.ErrorMsg
99 : blume 286 structure FNP = FilenamePolicy
100 : blume 275
101 :     type source = Source.inputSource
102 : blume 297 type ast = GenericVC.Ast.dec
103 :     type region = GenericVC.SourceMap.region
104 : blume 274
105 : blume 295 type complainer = EM.complainer
106 : blume 274
107 : blume 537 type attribs =
108 : blume 592 { split: bool,
109 :     is_rts: bool,
110 :     explicit_core_sym: Symbol.symbol option,
111 : blume 537 extra_compenv: GenericVC.Environment.staticEnv option }
112 :    
113 : blume 487 type generation = unit ref
114 :    
115 : blume 389 (* sh_mode is an elaboration of sh_spec; it must be persistent
116 :     * and gets properly re-computed when there is a new sh_spec *)
117 : blume 297 datatype persinfo =
118 : blume 666 PERS of { group: SrcPath.file * region,
119 : blume 487 generation: generation ref,
120 : blume 297 lastseen: TStamp.t ref,
121 : blume 299 parsetree: (ast * source) option ref,
122 : blume 389 skeleton: Skeleton.decl option ref,
123 :     sh_mode: Sharing.mode ref }
124 : blume 297
125 : blume 275 datatype info =
126 : blume 666 INFO of { sourcepath: SrcPath.file,
127 : blume 361 mkSkelname: unit -> string,
128 :     mkBinname: unit -> string,
129 : blume 297 persinfo: persinfo,
130 : blume 387 sh_spec: Sharing.request,
131 : blume 537 attribs: attribs }
132 : blume 270
133 : blume 305 type ord_key = info
134 :    
135 : blume 487 local
136 :     val generation = ref (ref ())
137 :     in
138 :     fun now () = !generation
139 :     fun newGeneration () = generation := ref ()
140 :     end
141 :    
142 : blume 277 fun sourcepath (INFO { sourcepath = sp, ... }) = sp
143 : blume 361 fun skelname (INFO { mkSkelname = msn, ... }) = msn ()
144 :     fun binname (INFO { mkBinname = mbn, ... }) = mbn ()
145 : blume 387 fun sh_spec (INFO { sh_spec = s, ... }) = s
146 : blume 389 fun sh_mode (INFO { persinfo = PERS { sh_mode = ref m, ... }, ... }) = m
147 :     fun set_sh_mode (INFO { persinfo = PERS { sh_mode, ... }, ... }, m) =
148 :     sh_mode := m
149 : blume 537 fun attribs (INFO { attribs = a, ... }) = a
150 : blume 270
151 : blume 299 fun gerror (gp: GeneralParams.info) = GroupReg.error (#groupreg gp)
152 : blume 297
153 :     fun error gp (INFO { persinfo = PERS { group, ... }, ... }) =
154 :     gerror gp group
155 :    
156 : blume 632 fun group (INFO { persinfo = PERS { group = (g, _), ... }, ... }) = g
157 :    
158 : blume 279 fun compare (INFO { sourcepath = p, ... }, INFO { sourcepath = p', ... }) =
159 : blume 354 SrcPath.compare (p, p')
160 : blume 279 fun eq (i, i') = compare (i, i') = EQUAL
161 :    
162 : blume 301 fun lastseen (INFO { persinfo = PERS { lastseen, ... }, ... }) =
163 :     !lastseen
164 :    
165 : blume 354 val knownInfo = ref (SrcPathMap.empty: persinfo SrcPathMap.map)
166 : blume 277
167 : blume 537 fun isKnown (INFO { sourcepath, ... }) =
168 :     isSome (SrcPathMap.find (!knownInfo, sourcepath))
169 :    
170 : blume 365 fun countParseTrees () = let
171 :     fun one (PERS { parsetree = ref (SOME _), ... }, i) = i + 1
172 :     | one (_, i) = i
173 :     in
174 :     SrcPathMap.foldl one 0 (!knownInfo)
175 :     end
176 :    
177 : blume 301 fun forgetParsetree (INFO { persinfo = PERS { parsetree, ... }, ... }) =
178 :     parsetree := NONE
179 :    
180 : blume 514 fun cleanGroup nowStable g = let
181 : blume 487 val n = now ()
182 :     fun isCurrent (PERS { generation = ref gen, group = (g', _), ... }) =
183 : blume 514 ((not nowStable) andalso gen = n)
184 :     orelse SrcPath.compare (g, g') <> EQUAL
185 : blume 301 in
186 : blume 487 knownInfo := SrcPathMap.filter isCurrent (!knownInfo)
187 : blume 301 end
188 :    
189 : blume 487 fun reset () = knownInfo := SrcPathMap.empty
190 :    
191 : blume 330 (* check timestamp and throw away any invalid cache *)
192 :     fun validate (sourcepath, PERS pir) = let
193 :     (* don't use "..." pattern to have the compiler catch later
194 :     * additions to the type! *)
195 : blume 487 val { group, lastseen, parsetree, skeleton, sh_mode, generation } = pir
196 : blume 330 val ts = !lastseen
197 : blume 354 val nts = SrcPath.tstamp sourcepath
198 : blume 330 in
199 : blume 345 if TStamp.needsUpdate { source = nts, target = ts } then
200 : blume 330 (lastseen := nts;
201 : blume 487 generation := now ();
202 : blume 330 parsetree := NONE;
203 :     skeleton := NONE)
204 :     else ()
205 :     end
206 :    
207 : blume 537 fun info' attribs (gp: GeneralParams.info) arg = let
208 :     val { sourcepath, group = gr as (group, region), sh_spec } = arg
209 : blume 310 val policy = #fnpolicy (#param gp)
210 : blume 361 fun mkSkelname () = FNP.mkSkelName policy sourcepath
211 :     fun mkBinname () = FNP.mkBinName policy sourcepath
212 : blume 297 val groupreg = #groupreg gp
213 :     fun newpersinfo () = let
214 : blume 354 val ts = SrcPath.tstamp sourcepath
215 : blume 330 val pi = PERS { group = gr, lastseen = ref ts,
216 : blume 389 parsetree = ref NONE, skeleton = ref NONE,
217 : blume 487 sh_mode = ref (Sharing.SHARE false),
218 :     generation = ref (now ()) }
219 : blume 281 in
220 : blume 354 knownInfo := SrcPathMap.insert (!knownInfo, sourcepath, pi);
221 : blume 297 pi
222 : blume 281 end
223 : blume 297 fun persinfo () =
224 : blume 354 case SrcPathMap.find (!knownInfo, sourcepath) of
225 : blume 297 NONE => newpersinfo ()
226 : blume 487 | SOME (pi as PERS { group = gr' as (g, r), generation, ... }) =>
227 : blume 354 if SrcPath.compare (group, g) <> EQUAL then let
228 :     val n = SrcPath.descr sourcepath
229 : blume 322 in
230 : blume 487 if !generation = now () then
231 : blume 322 (gerror gp gr EM.COMPLAIN
232 :     (concat ["ML source file ", n,
233 :     " appears in more than one group"])
234 :     EM.nullErrorBody;
235 :     gerror gp gr' EM.COMPLAIN
236 :     (concat ["(previous occurence of ", n, ")"])
237 :     EM.nullErrorBody)
238 :     else
239 :     gerror gp gr EM.WARN
240 :     (concat ["ML source file ", n,
241 :     " has switched groups"])
242 :     EM.nullErrorBody;
243 :     newpersinfo ()
244 :     end
245 : blume 330 else (validate (sourcepath, pi); pi)
246 : blume 281 in
247 : blume 297 INFO { sourcepath = sourcepath,
248 : blume 361 mkSkelname = mkSkelname,
249 :     mkBinname = mkBinname,
250 : blume 297 persinfo = persinfo (),
251 : blume 387 sh_spec = sh_spec,
252 : blume 537 attribs = attribs }
253 : blume 281 end
254 : blume 277
255 : blume 592 val info = info' { split = true, extra_compenv = NONE,
256 :     is_rts = false, explicit_core_sym = NONE }
257 : blume 537
258 : blume 275 (* the following functions are only concerned with getting the data,
259 :     * not with checking time stamps *)
260 : blume 297 fun getParseTree gp (i as INFO ir, quiet, noerrors) = let
261 :     val { sourcepath, persinfo = PERS { parsetree, ... }, ... } = ir
262 : blume 281 val err = if noerrors then (fn m => ())
263 : blume 297 else (fn m => error gp i EM.COMPLAIN m EM.nullErrorBody)
264 : blume 274 in
265 : blume 275 case !parsetree of
266 :     SOME pt => SOME pt
267 :     | NONE => let
268 : blume 345 fun work stream = let
269 :     val _ = if noerrors orelse quiet then ()
270 : blume 354 else Say.vsay ["[parsing ",
271 :     SrcPath.descr sourcepath, "]\n"]
272 : blume 345 val source =
273 : blume 492 Source.newSource (SrcPath.osstring' sourcepath,
274 : blume 354 1, stream, false, #errcons gp)
275 : blume 275 in
276 : blume 345 (SF.parse source, source)
277 :     end
278 : blume 364 fun openIt () = TextIO.openIn (SrcPath.osstring sourcepath)
279 : blume 345 val pto =
280 :     SOME (SafeIO.perform { openIt = openIt,
281 :     closeIt = TextIO.closeIn,
282 :     work = work,
283 : blume 459 cleanup = fn _ => () })
284 : blume 365 (* Counting the trees explicitly may be a bit slow,
285 :     * but maintaining an accurate count is difficult, so
286 :     * this method should be robust. (I don't think that
287 :     * the overhead of counting will make a noticeable
288 :     * difference.) *)
289 :     val ntrees = countParseTrees ()
290 : blume 433 val treelimit = #get StdConfig.parse_caching ()
291 : blume 275 in
292 : blume 365 if ntrees < treelimit then
293 :     parsetree := pto
294 :     else ();
295 : blume 275 pto
296 : blume 345 end handle exn as IO.Io _ => (err (General.exnMessage exn); NONE)
297 :     | SF.Compile msg => (err msg; NONE)
298 : blume 274 end
299 :    
300 : blume 297 fun getSkeleton gp (i as INFO ir, noerrors) = let
301 : blume 361 val { sourcepath, mkSkelname, persinfo = PERS pir, ... } = ir
302 : blume 297 val { skeleton, lastseen, ... } = pir
303 : blume 275 in
304 :     case !skeleton of
305 : blume 301 SOME sk => SOME sk
306 : blume 361 | NONE => let
307 :     val skelname = mkSkelname ()
308 :     in
309 :     case SkelIO.read (skelname, !lastseen) of
310 :     SOME sk => (skeleton := SOME sk; SOME sk)
311 :     | NONE =>
312 :     (case getParseTree gp (i, false, noerrors) of
313 :     SOME (tree, source) => let
314 :     fun err sv region s =
315 :     EM.error source region sv s
316 :     EM.nullErrorBody
317 :     val { skeleton = sk, complain } =
318 :     SkelCvt.convert { tree = tree,
319 :     err = err }
320 :     in
321 :     if noerrors then () else complain ();
322 : blume 310 if EM.anyErrors (EM.errors source) then
323 : blume 361 if noerrors then ()
324 :     else error gp i EM.COMPLAIN
325 : blume 310 "error(s) in ML source file"
326 :     EM.nullErrorBody
327 : blume 354 else (SkelIO.write (skelname, sk, !lastseen);
328 : blume 310 skeleton := SOME sk);
329 :     SOME sk
330 : blume 361 end
331 :     | NONE => NONE)
332 :     end
333 : blume 275 end
334 :    
335 : blume 330 fun skeleton0 noerrors gp i = getSkeleton gp (i, noerrors)
336 : blume 281
337 :     (* we only complain at the time of getting the exports *)
338 : blume 301 fun exports gp i = Option.map SkelExports.exports (skeleton0 false gp i)
339 : blume 281 val skeleton = skeleton0 true
340 : blume 275
341 : blume 330 fun parsetree gp i = getParseTree gp (i, true, true)
342 : blume 282
343 : blume 354 fun descr (INFO { sourcepath, ... }) = SrcPath.descr sourcepath
344 : blume 305
345 : blume 306 fun errorLocation (gp: GeneralParams.info) (INFO i) = let
346 :     val { persinfo = PERS { group = (group, reg), ... }, ... } = i
347 : blume 305 in
348 : blume 306 EM.matchErrorString (GroupReg.lookup (#groupreg gp) group) reg
349 : blume 305 end
350 : blume 270 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0